Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add _ObsoletedFeature
  • Loading branch information
isidentical committed Apr 23, 2020
commit 9670aa2900bc59bdb59b0059f2e8326393b75990
5 changes: 4 additions & 1 deletion Doc/library/__future__.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
can be inspected programmatically via importing :mod:`__future__` and examining
its contents.

Each statement in :file:`__future__.py` is of the form::
Each statement in :file:`__future__.py` is in one of these forms::

FeatureName = _Feature(OptionalRelease, MandatoryRelease,
CompilerFlag)

FeatureName = _ObsoletedFeature(OptionalRelease, MandatoryRelease,
CompilerFlag)


where, normally, *OptionalRelease* is less than *MandatoryRelease*, and both are
5-tuples of the same form as :data:`sys.version_info`::
Expand Down
7 changes: 5 additions & 2 deletions Lib/__future__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,14 @@ def __repr__(self):
self.mandatory,
self.compiler_flag))

nested_scopes = _Feature((2, 1, 0, "beta", 1),
class _ObsoletedFuture(_Feature):
pass

nested_scopes = _ObsoletedFuture((2, 1, 0, "beta", 1),
(2, 2, 0, "alpha", 0),
CO_NESTED)

generators = _Feature((2, 2, 0, "alpha", 1),
generators = _ObsoletedFuture((2, 2, 0, "alpha", 1),
(2, 3, 0, "final", 0),
CO_GENERATOR_ALLOWED)

Expand Down
15 changes: 13 additions & 2 deletions Lib/test/test___future__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,19 @@ def check(t, name):

a(hasattr(value, "compiler_flag"),
"feature is missing a .compiler_flag attr")
# Make sure the compile accepts the flag.
compile("", "<test>", "exec", value.compiler_flag)

if isinstance(value, __future__._ObsoletedFuture) and value.compiler_flag:
self.assertRaises(
ValueError,
compile,
"",
"<test>",
"exec",
value.compiler_flag
)
else:
# Make sure the compile accepts the flag.
compile("", "<test>", "exec", value.compiler_flag)
a(isinstance(getattr(value, "compiler_flag"), int),
".compiler_flag isn't int")

Expand Down