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