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

Skip to content

Commit ffc215a

Browse files
committed
Add __future__.py to std library, + dull test to verify that assignments
therein are of the proper form.
1 parent 32efcdb commit ffc215a

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

Lib/__future__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""__future__: Record of phased-in incompatible language changes.
2+
3+
Each line is of the form:
4+
5+
FeatureName = ReleaseInfo
6+
7+
ReleaseInfo is a pair of the form:
8+
9+
(OptionalRelease, MandatoryRelease)
10+
11+
where, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
12+
of the same form as sys.version_info:
13+
14+
(PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int
15+
PY_MINOR_VERSION, # the 1; an int
16+
PY_MICRO_VERSION, # the 0; an int
17+
PY_RELEASE_LEVEL, # "alpha", "beta", "candidate" or "final"; string
18+
PY_RELEASE_SERIAL # the 3; an int
19+
)
20+
21+
OptionalRelease records the first release in which
22+
23+
from __future__ import FeatureName
24+
25+
was accepted.
26+
27+
In the case of MandatoryReleases that have not yet occurred,
28+
MandatoryRelease predicts the release in which the feature will become part
29+
of the language.
30+
31+
Else MandatoryRelease records when the feature became part of the language;
32+
in releases at or after that, modules no longer need
33+
34+
from __future__ import FeatureName
35+
36+
to use the feature in question, but may continue to use such imports.
37+
38+
MandatoryRelease may also be None, meaning that a planned feature got
39+
dropped.
40+
41+
No line is ever to be deleted from this file.
42+
"""
43+
44+
nested_scopes = (2, 1, 0, "beta", 1), (2, 2, 0, "final", 0)

Lib/test/output/test___future__

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test___future__

Lib/test/test___future__.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#! /usr/bin/env python
2+
from test_support import verbose, verify
3+
from types import TupleType, StringType, IntType
4+
import __future__
5+
6+
GOOD_SERIALS = ("alpha", "beta", "candidate", "final")
7+
8+
features = [x for x in dir(__future__) if x[:1] != "_"]
9+
for feature in features:
10+
value = getattr(__future__, feature)
11+
if verbose:
12+
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")
15+
16+
optional, mandatory = value
17+
18+
verify(type(optional) is TupleType, "optional isn't tuple")
19+
verify(len(optional) == 5, "optional isn't 5-tuple")
20+
major, minor, micro, level, serial = optional
21+
verify(type(major) is IntType, "optional major isn't int")
22+
verify(type(minor) is IntType, "optional minor isn't int")
23+
verify(type(micro) is IntType, "optional micro isn't int")
24+
verify(type(level) is StringType, "optional level isn't string")
25+
verify(level in GOOD_SERIALS,
26+
"optional level string has unknown value")
27+
verify(type(serial) is IntType, "optional serial isn't int")
28+
29+
verify(type(mandatory) is TupleType or
30+
mandatory is None, "mandatory isn't tuple or None")
31+
if mandatory is not None:
32+
verify(len(mandatory) == 5, "mandatory isn't 5-tuple")
33+
major, minor, micro, level, serial = mandatory
34+
verify(type(major) is IntType, "mandatory major isn't int")
35+
verify(type(minor) is IntType, "mandatory minor isn't int")
36+
verify(type(micro) is IntType, "mandatory micro isn't int")
37+
verify(type(level) is StringType, "mandatory level isn't string")
38+
verify(level in GOOD_SERIALS,
39+
"mandatory serial string has unknown value")
40+
verify(type(serial) is IntType, "mandatory serial isn't int")
41+
verify(optional < mandatory,
42+
"optional not less than mandatory, and mandatory not None")

0 commit comments

Comments
 (0)