Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d74bc43

Browse files
committed
Make names in __future__.py bind to class instances instead of 2-tuples.
Suggested on c.l.py by William Tanksley, and I like it.
1 parent 239432a commit d74bc43

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

Lib/__future__.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
33
Each line is of the form:
44
5-
FeatureName = ReleaseInfo
6-
7-
ReleaseInfo is a pair of the form:
8-
9-
(OptionalRelease, MandatoryRelease)
5+
FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease) ")"
106
117
where, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
128
of the same form as sys.version_info:
@@ -38,7 +34,36 @@
3834
MandatoryRelease may also be None, meaning that a planned feature got
3935
dropped.
4036
41-
No line is ever to be deleted from this file.
37+
Instances of class _Feature have two corresponding methods,
38+
.getOptionalRelease() and .getMandatoryRelease().
39+
40+
No feature line is ever to be deleted from this file.
4241
"""
4342

44-
nested_scopes = (2, 1, 0, "beta", 1), (2, 2, 0, "final", 0)
43+
class _Feature:
44+
def __init__(self, optionalRelease, mandatoryRelease):
45+
self.optional = optionalRelease
46+
self.mandatory = mandatoryRelease
47+
48+
def getOptionalRelease(self):
49+
"""Return first release in which this feature was recognized.
50+
51+
This is a 5-tuple, of the same form as sys.version_info.
52+
"""
53+
54+
return self.optional
55+
56+
def getMandatoryRelease(self):
57+
"""Return release in which this feature will become mandatory.
58+
59+
This is a 5-tuple, of the same form as sys.version_info, or, if
60+
the feature was dropped, is None.
61+
"""
62+
63+
return self.mandatory
64+
65+
def __repr__(self):
66+
return "Feature(" + `self.getOptionalRelease()` + ", " + \
67+
`self.getMandatoryRelease()` + ")"
68+
69+
nested_scopes = _Feature((2, 1, 0, "beta", 1), (2, 2, 0, "final", 0))

Lib/test/test___future__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
value = getattr(__future__, feature)
1111
if verbose:
1212
print "Checking __future__ ", feature, "value", value
13-
verify(type(value) is TupleType, "feature value isn't tuple")
14-
verify(len(value) == 2, "feature value isn't 2-tuple")
1513

16-
optional, mandatory = value
14+
optional = value.getOptionalRelease()
15+
mandatory = value.getMandatoryRelease()
1716

1817
verify(type(optional) is TupleType, "optional isn't tuple")
1918
verify(len(optional) == 5, "optional isn't 5-tuple")

0 commit comments

Comments
 (0)