ยปCore Development>Code coverage>Lib/__future__.py

Python code coverage for Lib/__future__.py

#countcontent
1n/a"""Record of phased-in incompatible language changes.
2n/a
3n/aEach line is of the form:
4n/a
5n/a FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease ","
6n/a CompilerFlag ")"
7n/a
8n/awhere, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
9n/aof the same form as sys.version_info:
10n/a
11n/a (PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int
12n/a PY_MINOR_VERSION, # the 1; an int
13n/a PY_MICRO_VERSION, # the 0; an int
14n/a PY_RELEASE_LEVEL, # "alpha", "beta", "candidate" or "final"; string
15n/a PY_RELEASE_SERIAL # the 3; an int
16n/a )
17n/a
18n/aOptionalRelease records the first release in which
19n/a
20n/a from __future__ import FeatureName
21n/a
22n/awas accepted.
23n/a
24n/aIn the case of MandatoryReleases that have not yet occurred,
25n/aMandatoryRelease predicts the release in which the feature will become part
26n/aof the language.
27n/a
28n/aElse MandatoryRelease records when the feature became part of the language;
29n/ain releases at or after that, modules no longer need
30n/a
31n/a from __future__ import FeatureName
32n/a
33n/ato use the feature in question, but may continue to use such imports.
34n/a
35n/aMandatoryRelease may also be None, meaning that a planned feature got
36n/adropped.
37n/a
38n/aInstances of class _Feature have two corresponding methods,
39n/a.getOptionalRelease() and .getMandatoryRelease().
40n/a
41n/aCompilerFlag is the (bitfield) flag that should be passed in the fourth
42n/aargument to the builtin function compile() to enable the feature in
43n/adynamically compiled code. This flag is stored in the .compiler_flag
44n/aattribute on _Future instances. These values must match the appropriate
45n/a#defines of CO_xxx flags in Include/compile.h.
46n/a
47n/aNo feature line is ever to be deleted from this file.
48n/a"""
49n/a
50n/aall_feature_names = [
51n/a "nested_scopes",
52n/a "generators",
53n/a "division",
54n/a "absolute_import",
55n/a "with_statement",
56n/a "print_function",
57n/a "unicode_literals",
58n/a "barry_as_FLUFL",
59n/a "generator_stop",
60n/a]
61n/a
62n/a__all__ = ["all_feature_names"] + all_feature_names
63n/a
64n/a# The CO_xxx symbols are defined here under the same names used by
65n/a# compile.h, so that an editor search will find them here. However,
66n/a# they're not exported in __all__, because they don't really belong to
67n/a# this module.
68n/aCO_NESTED = 0x0010 # nested_scopes
69n/aCO_GENERATOR_ALLOWED = 0 # generators (obsolete, was 0x1000)
70n/aCO_FUTURE_DIVISION = 0x2000 # division
71n/aCO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default
72n/aCO_FUTURE_WITH_STATEMENT = 0x8000 # with statement
73n/aCO_FUTURE_PRINT_FUNCTION = 0x10000 # print function
74n/aCO_FUTURE_UNICODE_LITERALS = 0x20000 # unicode string literals
75n/aCO_FUTURE_BARRY_AS_BDFL = 0x40000
76n/aCO_FUTURE_GENERATOR_STOP = 0x80000 # StopIteration becomes RuntimeError in generators
77n/a
78n/aclass _Feature:
79n/a def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
80n/a self.optional = optionalRelease
81n/a self.mandatory = mandatoryRelease
82n/a self.compiler_flag = compiler_flag
83n/a
84n/a def getOptionalRelease(self):
85n/a """Return first release in which this feature was recognized.
86n/a
87n/a This is a 5-tuple, of the same form as sys.version_info.
88n/a """
89n/a
90n/a return self.optional
91n/a
92n/a def getMandatoryRelease(self):
93n/a """Return release in which this feature will become mandatory.
94n/a
95n/a This is a 5-tuple, of the same form as sys.version_info, or, if
96n/a the feature was dropped, is None.
97n/a """
98n/a
99n/a return self.mandatory
100n/a
101n/a def __repr__(self):
102n/a return "_Feature" + repr((self.optional,
103n/a self.mandatory,
104n/a self.compiler_flag))
105n/a
106n/anested_scopes = _Feature((2, 1, 0, "beta", 1),
107n/a (2, 2, 0, "alpha", 0),
108n/a CO_NESTED)
109n/a
110n/agenerators = _Feature((2, 2, 0, "alpha", 1),
111n/a (2, 3, 0, "final", 0),
112n/a CO_GENERATOR_ALLOWED)
113n/a
114n/adivision = _Feature((2, 2, 0, "alpha", 2),
115n/a (3, 0, 0, "alpha", 0),
116n/a CO_FUTURE_DIVISION)
117n/a
118n/aabsolute_import = _Feature((2, 5, 0, "alpha", 1),
119n/a (3, 0, 0, "alpha", 0),
120n/a CO_FUTURE_ABSOLUTE_IMPORT)
121n/a
122n/awith_statement = _Feature((2, 5, 0, "alpha", 1),
123n/a (2, 6, 0, "alpha", 0),
124n/a CO_FUTURE_WITH_STATEMENT)
125n/a
126n/aprint_function = _Feature((2, 6, 0, "alpha", 2),
127n/a (3, 0, 0, "alpha", 0),
128n/a CO_FUTURE_PRINT_FUNCTION)
129n/a
130n/aunicode_literals = _Feature((2, 6, 0, "alpha", 2),
131n/a (3, 0, 0, "alpha", 0),
132n/a CO_FUTURE_UNICODE_LITERALS)
133n/a
134n/abarry_as_FLUFL = _Feature((3, 1, 0, "alpha", 2),
135n/a (3, 9, 0, "alpha", 0),
136n/a CO_FUTURE_BARRY_AS_BDFL)
137n/a
138n/agenerator_stop = _Feature((3, 5, 0, "beta", 1),
139n/a (3, 7, 0, "alpha", 0),
140n/a CO_FUTURE_GENERATOR_STOP)