Skip to content

Commit fdc91c2

Browse files
bpo-41314: fixed annotations __future__ version (GH-21616)
PEP 563 was updated to change the release where `from __future__ import annotations` becomes the default (and only) behavior from 4.0 to 3.10. Update `__future__.py` and its docs to reflect this. (cherry picked from commit 0028c14) Co-authored-by: YoSTEALTH <[email protected]>
1 parent 2024d7a commit fdc91c2

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

Doc/library/__future__.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ language using this mechanism:
9090
| generator_stop | 3.5.0b1 | 3.7 | :pep:`479`: |
9191
| | | | *StopIteration handling inside generators* |
9292
+------------------+-------------+--------------+---------------------------------------------+
93-
| annotations | 3.7.0b1 | 4.0 | :pep:`563`: |
93+
| annotations | 3.7.0b1 | 3.10 | :pep:`563`: |
9494
| | | | *Postponed evaluation of annotations* |
9595
+------------------+-------------+--------------+---------------------------------------------+
9696

Lib/__future__.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,20 @@
6666
# code.h and used by compile.h, so that an editor search will find them here.
6767
# However, they're not exported in __all__, because they don't really belong to
6868
# this module.
69-
CO_NESTED = 0x0010 # nested_scopes
70-
CO_GENERATOR_ALLOWED = 0 # generators (obsolete, was 0x1000)
71-
CO_FUTURE_DIVISION = 0x20000 # division
72-
CO_FUTURE_ABSOLUTE_IMPORT = 0x40000 # perform absolute imports by default
73-
CO_FUTURE_WITH_STATEMENT = 0x80000 # with statement
74-
CO_FUTURE_PRINT_FUNCTION = 0x100000 # print function
75-
CO_FUTURE_UNICODE_LITERALS = 0x200000 # unicode string literals
69+
CO_NESTED = 0x0010 # nested_scopes
70+
CO_GENERATOR_ALLOWED = 0 # generators (obsolete, was 0x1000)
71+
CO_FUTURE_DIVISION = 0x20000 # division
72+
CO_FUTURE_ABSOLUTE_IMPORT = 0x40000 # perform absolute imports by default
73+
CO_FUTURE_WITH_STATEMENT = 0x80000 # with statement
74+
CO_FUTURE_PRINT_FUNCTION = 0x100000 # print function
75+
CO_FUTURE_UNICODE_LITERALS = 0x200000 # unicode string literals
7676
CO_FUTURE_BARRY_AS_BDFL = 0x400000
77-
CO_FUTURE_GENERATOR_STOP = 0x800000 # StopIteration becomes RuntimeError in generators
78-
CO_FUTURE_ANNOTATIONS = 0x1000000 # annotations become strings at runtime
77+
CO_FUTURE_GENERATOR_STOP = 0x800000 # StopIteration becomes RuntimeError in generators
78+
CO_FUTURE_ANNOTATIONS = 0x1000000 # annotations become strings at runtime
79+
7980

8081
class _Feature:
82+
8183
def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
8284
self.optional = optionalRelease
8385
self.mandatory = mandatoryRelease
@@ -88,7 +90,6 @@ def getOptionalRelease(self):
8890
8991
This is a 5-tuple, of the same form as sys.version_info.
9092
"""
91-
9293
return self.optional
9394

9495
def getMandatoryRelease(self):
@@ -97,14 +98,14 @@ def getMandatoryRelease(self):
9798
This is a 5-tuple, of the same form as sys.version_info, or, if
9899
the feature was dropped, is None.
99100
"""
100-
101101
return self.mandatory
102102

103103
def __repr__(self):
104104
return "_Feature" + repr((self.optional,
105105
self.mandatory,
106106
self.compiler_flag))
107107

108+
108109
nested_scopes = _Feature((2, 1, 0, "beta", 1),
109110
(2, 2, 0, "alpha", 0),
110111
CO_NESTED)
@@ -142,5 +143,5 @@ def __repr__(self):
142143
CO_FUTURE_GENERATOR_STOP)
143144

144145
annotations = _Feature((3, 7, 0, "beta", 1),
145-
(4, 0, 0, "alpha", 0),
146+
(3, 10, 0, "alpha", 0),
146147
CO_FUTURE_ANNOTATIONS)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Changed the release when ``from __future__ import annotations`` becomes the default from ``4.0`` to ``3.10`` (following a change in PEP 563).

0 commit comments

Comments
 (0)