annotate Lib/__future__.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents f9f4bdcbc25a
children 2a2d46d1929a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17044
6ca72d71536e Remove redundant "__future__:" from module docstring.
Ka-Ping Yee <ping@zesty.ca>
parents: 16931
diff changeset
1 """Record of phased-in incompatible language changes.
16770
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
2
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
3 Each line is of the form:
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
4
19345
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
5 FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease ","
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
6 CompilerFlag ")"
16770
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
7
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
8 where, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
9 of the same form as sys.version_info:
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
10
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
11 (PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
12 PY_MINOR_VERSION, # the 1; an int
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
13 PY_MICRO_VERSION, # the 0; an int
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
14 PY_RELEASE_LEVEL, # "alpha", "beta", "candidate" or "final"; string
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
15 PY_RELEASE_SERIAL # the 3; an int
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
16 )
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
17
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
18 OptionalRelease records the first release in which
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
19
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
20 from __future__ import FeatureName
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
21
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
22 was accepted.
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
23
16833
bbdeb6d4dea1 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 16770
diff changeset
24 In the case of MandatoryReleases that have not yet occurred,
bbdeb6d4dea1 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 16770
diff changeset
25 MandatoryRelease predicts the release in which the feature will become part
16770
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
26 of the language.
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
27
16833
bbdeb6d4dea1 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 16770
diff changeset
28 Else MandatoryRelease records when the feature became part of the language;
16770
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
29 in releases at or after that, modules no longer need
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
30
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
31 from __future__ import FeatureName
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
32
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
33 to use the feature in question, but may continue to use such imports.
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
34
16833
bbdeb6d4dea1 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 16770
diff changeset
35 MandatoryRelease may also be None, meaning that a planned feature got
16770
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
36 dropped.
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
37
16929
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
38 Instances of class _Feature have two corresponding methods,
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
39 .getOptionalRelease() and .getMandatoryRelease().
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
40
19345
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
41 CompilerFlag is the (bitfield) flag that should be passed in the fourth
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
42 argument to the builtin function compile() to enable the feature in
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
43 dynamically compiled code. This flag is stored in the .compiler_flag
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
44 attribute on _Future instances. These values must match the appropriate
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
45 #defines of CO_xxx flags in Include/compile.h.
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
46
16929
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
47 No feature line is ever to be deleted from this file.
16770
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
48 """
14affbd03750 Add __future__.py to std library, + dull test to verify that assignments
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
49
19345
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
50 all_feature_names = [
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
51 "nested_scopes",
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
52 "generators",
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
53 "division",
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
54 ]
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
55
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
56 __all__ = ["all_feature_names"] + all_feature_names
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
57
19461
f7aaf721a81b Back out trying to use the C values for CO_xxx.
Tim Peters <tim.peters@gmail.com>
parents: 19378
diff changeset
58 # The CO_xxx symbols are defined here under the same names used by
f7aaf721a81b Back out trying to use the C values for CO_xxx.
Tim Peters <tim.peters@gmail.com>
parents: 19378
diff changeset
59 # compile.h, so that an editor search will find them here. However,
f7aaf721a81b Back out trying to use the C values for CO_xxx.
Tim Peters <tim.peters@gmail.com>
parents: 19378
diff changeset
60 # they're not exported in __all__, because they don't really belong to
f7aaf721a81b Back out trying to use the C values for CO_xxx.
Tim Peters <tim.peters@gmail.com>
parents: 19378
diff changeset
61 # this module.
f7aaf721a81b Back out trying to use the C values for CO_xxx.
Tim Peters <tim.peters@gmail.com>
parents: 19378
diff changeset
62 CO_NESTED = 0x0010 # nested_scopes
f7aaf721a81b Back out trying to use the C values for CO_xxx.
Tim Peters <tim.peters@gmail.com>
parents: 19378
diff changeset
63 CO_GENERATOR_ALLOWED = 0x1000 # generators
f7aaf721a81b Back out trying to use the C values for CO_xxx.
Tim Peters <tim.peters@gmail.com>
parents: 19378
diff changeset
64 CO_FUTURE_DIVISION = 0x2000 # division
19345
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
65
16929
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
66 class _Feature:
19345
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
67 def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
16929
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
68 self.optional = optionalRelease
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
69 self.mandatory = mandatoryRelease
19345
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
70 self.compiler_flag = compiler_flag
16929
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
71
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
72 def getOptionalRelease(self):
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
73 """Return first release in which this feature was recognized.
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
74
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
75 This is a 5-tuple, of the same form as sys.version_info.
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
76 """
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
77
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
78 return self.optional
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
79
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
80 def getMandatoryRelease(self):
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
81 """Return release in which this feature will become mandatory.
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
82
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
83 This is a 5-tuple, of the same form as sys.version_info, or, if
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
84 the feature was dropped, is None.
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
85 """
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
86
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
87 return self.mandatory
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
88
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
89 def __repr__(self):
19474
f9f4bdcbc25a Repair repr of future-features (wasn't updated to include the new
Tim Peters <tim.peters@gmail.com>
parents: 19461
diff changeset
90 return "_Feature" + repr((self.optional,
f9f4bdcbc25a Repair repr of future-features (wasn't updated to include the new
Tim Peters <tim.peters@gmail.com>
parents: 19461
diff changeset
91 self.mandatory,
f9f4bdcbc25a Repair repr of future-features (wasn't updated to include the new
Tim Peters <tim.peters@gmail.com>
parents: 19461
diff changeset
92 self.compiler_flag))
19345
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
93
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
94 nested_scopes = _Feature((2, 1, 0, "beta", 1),
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
95 (2, 2, 0, "alpha", 0),
19461
f7aaf721a81b Back out trying to use the C values for CO_xxx.
Tim Peters <tim.peters@gmail.com>
parents: 19378
diff changeset
96 CO_NESTED)
16929
3a2e8a3ede48 Make names in __future__.py bind to class instances instead of 2-tuples.
Tim Peters <tim.peters@gmail.com>
parents: 16833
diff changeset
97
19345
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
98 generators = _Feature((2, 2, 0, "alpha", 1),
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
99 (2, 3, 0, "final", 0),
19461
f7aaf721a81b Back out trying to use the C values for CO_xxx.
Tim Peters <tim.peters@gmail.com>
parents: 19378
diff changeset
100 CO_GENERATOR_ALLOWED)
19345
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
101
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
102 division = _Feature((2, 2, 0, "alpha", 2),
38be177bd493 A self-contained piece of Michael Hudson's patch
Tim Peters <tim.peters@gmail.com>
parents: 19051
diff changeset
103 (3, 0, 0, "alpha", 0),
19461
f7aaf721a81b Back out trying to use the C values for CO_xxx.
Tim Peters <tim.peters@gmail.com>
parents: 19378
diff changeset
104 CO_FUTURE_DIVISION)