A self-contained piece of Michael Hudson's patch
#449043 supporting __future__ in simulated shells in support of PEP 264. Much has changed from the patch version: + Repaired bad hex constant for nested_scopes. + Defined symbolic CO_xxx names so global search will find these uses. + Made the exported list of feature names explicit, instead of abusing __all__ for this purpose (and redefined __all__ accordingly). + Added gross .compiler_flag verification to test___future__.py, and reworked it a little to make use of the newly exported explicit list of feature names.
This commit is contained in:
parent
b0a98e9c94
commit
de642bdc5d
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
Each line is of the form:
|
Each line is of the form:
|
||||||
|
|
||||||
FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease ")"
|
FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease ","
|
||||||
|
CompilerFlag ")"
|
||||||
|
|
||||||
where, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
|
where, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
|
||||||
of the same form as sys.version_info:
|
of the same form as sys.version_info:
|
||||||
|
@ -37,13 +38,37 @@ dropped.
|
||||||
Instances of class _Feature have two corresponding methods,
|
Instances of class _Feature have two corresponding methods,
|
||||||
.getOptionalRelease() and .getMandatoryRelease().
|
.getOptionalRelease() and .getMandatoryRelease().
|
||||||
|
|
||||||
|
CompilerFlag is the (bitfield) flag that should be passed in the fourth
|
||||||
|
argument to the builtin function compile() to enable the feature in
|
||||||
|
dynamically compiled code. This flag is stored in the .compiler_flag
|
||||||
|
attribute on _Future instances. These values must match the appropriate
|
||||||
|
#defines of CO_xxx flags in Include/compile.h.
|
||||||
|
|
||||||
No feature line is ever to be deleted from this file.
|
No feature line is ever to be deleted from this file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
all_feature_names = [
|
||||||
|
"nested_scopes",
|
||||||
|
"generators",
|
||||||
|
"division",
|
||||||
|
]
|
||||||
|
|
||||||
|
__all__ = ["all_feature_names"] + all_feature_names
|
||||||
|
|
||||||
|
|
||||||
|
# The CO_xxx symbols are defined here under the same names used by
|
||||||
|
# compile.h, so that an editor search will find them here. However,
|
||||||
|
# they're not exported in __all__, because they don't really belong to
|
||||||
|
# this module.
|
||||||
|
CO_NESTED = 0x0010 # nested_scopes
|
||||||
|
CO_GENERATOR_ALLOWED = 0x1000 # generators
|
||||||
|
CO_FUTURE_DIVISION = 0x2000 # division
|
||||||
|
|
||||||
class _Feature:
|
class _Feature:
|
||||||
def __init__(self, optionalRelease, mandatoryRelease):
|
def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
|
||||||
self.optional = optionalRelease
|
self.optional = optionalRelease
|
||||||
self.mandatory = mandatoryRelease
|
self.mandatory = mandatoryRelease
|
||||||
|
self.compiler_flag = compiler_flag
|
||||||
|
|
||||||
def getOptionalRelease(self):
|
def getOptionalRelease(self):
|
||||||
"""Return first release in which this feature was recognized.
|
"""Return first release in which this feature was recognized.
|
||||||
|
@ -63,9 +88,17 @@ class _Feature:
|
||||||
return self.mandatory
|
return self.mandatory
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "Feature(" + `self.getOptionalRelease()` + ", " + \
|
return "_Feature(" + `self.getOptionalRelease()` + ", " + \
|
||||||
`self.getMandatoryRelease()` + ")"
|
`self.getMandatoryRelease()` + ")"
|
||||||
|
|
||||||
nested_scopes = _Feature((2, 1, 0, "beta", 1), (2, 2, 0, "alpha", 0))
|
nested_scopes = _Feature((2, 1, 0, "beta", 1),
|
||||||
generators = _Feature((2, 2, 0, "alpha", 1), (2, 3, 0, "final", 0))
|
(2, 2, 0, "alpha", 0),
|
||||||
division = _Feature((2, 2, 0, "alpha", 2), (3, 0, 0, "alpha", 0))
|
CO_NESTED)
|
||||||
|
|
||||||
|
generators = _Feature((2, 2, 0, "alpha", 1),
|
||||||
|
(2, 3, 0, "final", 0),
|
||||||
|
CO_GENERATOR_ALLOWED)
|
||||||
|
|
||||||
|
division = _Feature((2, 2, 0, "alpha", 2),
|
||||||
|
(3, 0, 0, "alpha", 0),
|
||||||
|
CO_FUTURE_DIVISION)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import __future__
|
||||||
|
|
||||||
GOOD_SERIALS = ("alpha", "beta", "candidate", "final")
|
GOOD_SERIALS = ("alpha", "beta", "candidate", "final")
|
||||||
|
|
||||||
features = [x for x in dir(__future__) if x[:1] != "_"]
|
features = __future__.all_feature_names
|
||||||
for feature in features:
|
for feature in features:
|
||||||
value = getattr(__future__, feature)
|
value = getattr(__future__, feature)
|
||||||
if verbose:
|
if verbose:
|
||||||
|
@ -39,3 +39,8 @@ for feature in features:
|
||||||
verify(type(serial) is IntType, "mandatory serial isn't int")
|
verify(type(serial) is IntType, "mandatory serial isn't int")
|
||||||
verify(optional < mandatory,
|
verify(optional < mandatory,
|
||||||
"optional not less than mandatory, and mandatory not None")
|
"optional not less than mandatory, and mandatory not None")
|
||||||
|
|
||||||
|
verify(hasattr(value, "compiler_flag"),
|
||||||
|
"feature is missing a .compiler_flag attr")
|
||||||
|
verify(type(getattr(value, "compiler_flag")) is IntType,
|
||||||
|
".compiler_flag isn't int")
|
||||||
|
|
Loading…
Reference in New Issue