xref: /aosp_15_r20/prebuilts/build-tools/common/py3-stdlib/__future__.py (revision cda5da8d549138a6648c5ee6d7a49cf8f4a657be)
1*cda5da8dSAndroid Build Coastguard Worker"""Record of phased-in incompatible language changes.
2*cda5da8dSAndroid Build Coastguard Worker
3*cda5da8dSAndroid Build Coastguard WorkerEach line is of the form:
4*cda5da8dSAndroid Build Coastguard Worker
5*cda5da8dSAndroid Build Coastguard Worker    FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease ","
6*cda5da8dSAndroid Build Coastguard Worker                              CompilerFlag ")"
7*cda5da8dSAndroid Build Coastguard Worker
8*cda5da8dSAndroid Build Coastguard Workerwhere, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
9*cda5da8dSAndroid Build Coastguard Workerof the same form as sys.version_info:
10*cda5da8dSAndroid Build Coastguard Worker
11*cda5da8dSAndroid Build Coastguard Worker    (PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int
12*cda5da8dSAndroid Build Coastguard Worker     PY_MINOR_VERSION, # the 1; an int
13*cda5da8dSAndroid Build Coastguard Worker     PY_MICRO_VERSION, # the 0; an int
14*cda5da8dSAndroid Build Coastguard Worker     PY_RELEASE_LEVEL, # "alpha", "beta", "candidate" or "final"; string
15*cda5da8dSAndroid Build Coastguard Worker     PY_RELEASE_SERIAL # the 3; an int
16*cda5da8dSAndroid Build Coastguard Worker    )
17*cda5da8dSAndroid Build Coastguard Worker
18*cda5da8dSAndroid Build Coastguard WorkerOptionalRelease records the first release in which
19*cda5da8dSAndroid Build Coastguard Worker
20*cda5da8dSAndroid Build Coastguard Worker    from __future__ import FeatureName
21*cda5da8dSAndroid Build Coastguard Worker
22*cda5da8dSAndroid Build Coastguard Workerwas accepted.
23*cda5da8dSAndroid Build Coastguard Worker
24*cda5da8dSAndroid Build Coastguard WorkerIn the case of MandatoryReleases that have not yet occurred,
25*cda5da8dSAndroid Build Coastguard WorkerMandatoryRelease predicts the release in which the feature will become part
26*cda5da8dSAndroid Build Coastguard Workerof the language.
27*cda5da8dSAndroid Build Coastguard Worker
28*cda5da8dSAndroid Build Coastguard WorkerElse MandatoryRelease records when the feature became part of the language;
29*cda5da8dSAndroid Build Coastguard Workerin releases at or after that, modules no longer need
30*cda5da8dSAndroid Build Coastguard Worker
31*cda5da8dSAndroid Build Coastguard Worker    from __future__ import FeatureName
32*cda5da8dSAndroid Build Coastguard Worker
33*cda5da8dSAndroid Build Coastguard Workerto use the feature in question, but may continue to use such imports.
34*cda5da8dSAndroid Build Coastguard Worker
35*cda5da8dSAndroid Build Coastguard WorkerMandatoryRelease may also be None, meaning that a planned feature got
36*cda5da8dSAndroid Build Coastguard Workerdropped or that the release version is undetermined.
37*cda5da8dSAndroid Build Coastguard Worker
38*cda5da8dSAndroid Build Coastguard WorkerInstances of class _Feature have two corresponding methods,
39*cda5da8dSAndroid Build Coastguard Worker.getOptionalRelease() and .getMandatoryRelease().
40*cda5da8dSAndroid Build Coastguard Worker
41*cda5da8dSAndroid Build Coastguard WorkerCompilerFlag is the (bitfield) flag that should be passed in the fourth
42*cda5da8dSAndroid Build Coastguard Workerargument to the builtin function compile() to enable the feature in
43*cda5da8dSAndroid Build Coastguard Workerdynamically compiled code.  This flag is stored in the .compiler_flag
44*cda5da8dSAndroid Build Coastguard Workerattribute on _Future instances.  These values must match the appropriate
45*cda5da8dSAndroid Build Coastguard Worker#defines of CO_xxx flags in Include/cpython/compile.h.
46*cda5da8dSAndroid Build Coastguard Worker
47*cda5da8dSAndroid Build Coastguard WorkerNo feature line is ever to be deleted from this file.
48*cda5da8dSAndroid Build Coastguard Worker"""
49*cda5da8dSAndroid Build Coastguard Worker
50*cda5da8dSAndroid Build Coastguard Workerall_feature_names = [
51*cda5da8dSAndroid Build Coastguard Worker    "nested_scopes",
52*cda5da8dSAndroid Build Coastguard Worker    "generators",
53*cda5da8dSAndroid Build Coastguard Worker    "division",
54*cda5da8dSAndroid Build Coastguard Worker    "absolute_import",
55*cda5da8dSAndroid Build Coastguard Worker    "with_statement",
56*cda5da8dSAndroid Build Coastguard Worker    "print_function",
57*cda5da8dSAndroid Build Coastguard Worker    "unicode_literals",
58*cda5da8dSAndroid Build Coastguard Worker    "barry_as_FLUFL",
59*cda5da8dSAndroid Build Coastguard Worker    "generator_stop",
60*cda5da8dSAndroid Build Coastguard Worker    "annotations",
61*cda5da8dSAndroid Build Coastguard Worker]
62*cda5da8dSAndroid Build Coastguard Worker
63*cda5da8dSAndroid Build Coastguard Worker__all__ = ["all_feature_names"] + all_feature_names
64*cda5da8dSAndroid Build Coastguard Worker
65*cda5da8dSAndroid Build Coastguard Worker# The CO_xxx symbols are defined here under the same names defined in
66*cda5da8dSAndroid Build Coastguard Worker# code.h and used by compile.h, so that an editor search will find them here.
67*cda5da8dSAndroid Build Coastguard Worker# However, they're not exported in __all__, because they don't really belong to
68*cda5da8dSAndroid Build Coastguard Worker# this module.
69*cda5da8dSAndroid Build Coastguard WorkerCO_NESTED = 0x0010                      # nested_scopes
70*cda5da8dSAndroid Build Coastguard WorkerCO_GENERATOR_ALLOWED = 0                # generators (obsolete, was 0x1000)
71*cda5da8dSAndroid Build Coastguard WorkerCO_FUTURE_DIVISION = 0x20000            # division
72*cda5da8dSAndroid Build Coastguard WorkerCO_FUTURE_ABSOLUTE_IMPORT = 0x40000     # perform absolute imports by default
73*cda5da8dSAndroid Build Coastguard WorkerCO_FUTURE_WITH_STATEMENT = 0x80000      # with statement
74*cda5da8dSAndroid Build Coastguard WorkerCO_FUTURE_PRINT_FUNCTION = 0x100000     # print function
75*cda5da8dSAndroid Build Coastguard WorkerCO_FUTURE_UNICODE_LITERALS = 0x200000   # unicode string literals
76*cda5da8dSAndroid Build Coastguard WorkerCO_FUTURE_BARRY_AS_BDFL = 0x400000
77*cda5da8dSAndroid Build Coastguard WorkerCO_FUTURE_GENERATOR_STOP = 0x800000     # StopIteration becomes RuntimeError in generators
78*cda5da8dSAndroid Build Coastguard WorkerCO_FUTURE_ANNOTATIONS = 0x1000000       # annotations become strings at runtime
79*cda5da8dSAndroid Build Coastguard Worker
80*cda5da8dSAndroid Build Coastguard Worker
81*cda5da8dSAndroid Build Coastguard Workerclass _Feature:
82*cda5da8dSAndroid Build Coastguard Worker
83*cda5da8dSAndroid Build Coastguard Worker    def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
84*cda5da8dSAndroid Build Coastguard Worker        self.optional = optionalRelease
85*cda5da8dSAndroid Build Coastguard Worker        self.mandatory = mandatoryRelease
86*cda5da8dSAndroid Build Coastguard Worker        self.compiler_flag = compiler_flag
87*cda5da8dSAndroid Build Coastguard Worker
88*cda5da8dSAndroid Build Coastguard Worker    def getOptionalRelease(self):
89*cda5da8dSAndroid Build Coastguard Worker        """Return first release in which this feature was recognized.
90*cda5da8dSAndroid Build Coastguard Worker
91*cda5da8dSAndroid Build Coastguard Worker        This is a 5-tuple, of the same form as sys.version_info.
92*cda5da8dSAndroid Build Coastguard Worker        """
93*cda5da8dSAndroid Build Coastguard Worker        return self.optional
94*cda5da8dSAndroid Build Coastguard Worker
95*cda5da8dSAndroid Build Coastguard Worker    def getMandatoryRelease(self):
96*cda5da8dSAndroid Build Coastguard Worker        """Return release in which this feature will become mandatory.
97*cda5da8dSAndroid Build Coastguard Worker
98*cda5da8dSAndroid Build Coastguard Worker        This is a 5-tuple, of the same form as sys.version_info, or, if
99*cda5da8dSAndroid Build Coastguard Worker        the feature was dropped, or the release date is undetermined, is None.
100*cda5da8dSAndroid Build Coastguard Worker        """
101*cda5da8dSAndroid Build Coastguard Worker        return self.mandatory
102*cda5da8dSAndroid Build Coastguard Worker
103*cda5da8dSAndroid Build Coastguard Worker    def __repr__(self):
104*cda5da8dSAndroid Build Coastguard Worker        return "_Feature" + repr((self.optional,
105*cda5da8dSAndroid Build Coastguard Worker                                  self.mandatory,
106*cda5da8dSAndroid Build Coastguard Worker                                  self.compiler_flag))
107*cda5da8dSAndroid Build Coastguard Worker
108*cda5da8dSAndroid Build Coastguard Worker
109*cda5da8dSAndroid Build Coastguard Workernested_scopes = _Feature((2, 1, 0, "beta",  1),
110*cda5da8dSAndroid Build Coastguard Worker                         (2, 2, 0, "alpha", 0),
111*cda5da8dSAndroid Build Coastguard Worker                         CO_NESTED)
112*cda5da8dSAndroid Build Coastguard Worker
113*cda5da8dSAndroid Build Coastguard Workergenerators = _Feature((2, 2, 0, "alpha", 1),
114*cda5da8dSAndroid Build Coastguard Worker                      (2, 3, 0, "final", 0),
115*cda5da8dSAndroid Build Coastguard Worker                      CO_GENERATOR_ALLOWED)
116*cda5da8dSAndroid Build Coastguard Worker
117*cda5da8dSAndroid Build Coastguard Workerdivision = _Feature((2, 2, 0, "alpha", 2),
118*cda5da8dSAndroid Build Coastguard Worker                    (3, 0, 0, "alpha", 0),
119*cda5da8dSAndroid Build Coastguard Worker                    CO_FUTURE_DIVISION)
120*cda5da8dSAndroid Build Coastguard Worker
121*cda5da8dSAndroid Build Coastguard Workerabsolute_import = _Feature((2, 5, 0, "alpha", 1),
122*cda5da8dSAndroid Build Coastguard Worker                           (3, 0, 0, "alpha", 0),
123*cda5da8dSAndroid Build Coastguard Worker                           CO_FUTURE_ABSOLUTE_IMPORT)
124*cda5da8dSAndroid Build Coastguard Worker
125*cda5da8dSAndroid Build Coastguard Workerwith_statement = _Feature((2, 5, 0, "alpha", 1),
126*cda5da8dSAndroid Build Coastguard Worker                          (2, 6, 0, "alpha", 0),
127*cda5da8dSAndroid Build Coastguard Worker                          CO_FUTURE_WITH_STATEMENT)
128*cda5da8dSAndroid Build Coastguard Worker
129*cda5da8dSAndroid Build Coastguard Workerprint_function = _Feature((2, 6, 0, "alpha", 2),
130*cda5da8dSAndroid Build Coastguard Worker                          (3, 0, 0, "alpha", 0),
131*cda5da8dSAndroid Build Coastguard Worker                          CO_FUTURE_PRINT_FUNCTION)
132*cda5da8dSAndroid Build Coastguard Worker
133*cda5da8dSAndroid Build Coastguard Workerunicode_literals = _Feature((2, 6, 0, "alpha", 2),
134*cda5da8dSAndroid Build Coastguard Worker                            (3, 0, 0, "alpha", 0),
135*cda5da8dSAndroid Build Coastguard Worker                            CO_FUTURE_UNICODE_LITERALS)
136*cda5da8dSAndroid Build Coastguard Worker
137*cda5da8dSAndroid Build Coastguard Workerbarry_as_FLUFL = _Feature((3, 1, 0, "alpha", 2),
138*cda5da8dSAndroid Build Coastguard Worker                          (4, 0, 0, "alpha", 0),
139*cda5da8dSAndroid Build Coastguard Worker                          CO_FUTURE_BARRY_AS_BDFL)
140*cda5da8dSAndroid Build Coastguard Worker
141*cda5da8dSAndroid Build Coastguard Workergenerator_stop = _Feature((3, 5, 0, "beta", 1),
142*cda5da8dSAndroid Build Coastguard Worker                          (3, 7, 0, "alpha", 0),
143*cda5da8dSAndroid Build Coastguard Worker                          CO_FUTURE_GENERATOR_STOP)
144*cda5da8dSAndroid Build Coastguard Worker
145*cda5da8dSAndroid Build Coastguard Workerannotations = _Feature((3, 7, 0, "beta", 1),
146*cda5da8dSAndroid Build Coastguard Worker                       None,
147*cda5da8dSAndroid Build Coastguard Worker                       CO_FUTURE_ANNOTATIONS)
148