]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-38605: Make 'from __future__ import annotations' the default (GH-20434)
authorBatuhan Taskaya <batuhanosmantaskaya@gmail.com>
Tue, 6 Oct 2020 20:03:02 +0000 (23:03 +0300)
committerGitHub <noreply@github.com>
Tue, 6 Oct 2020 20:03:02 +0000 (13:03 -0700)
commit044a1048ca93d466965afc027b91a5a9eb9ce23c
tree94ef2bca072693d83448edef4009dc840c58a3e2
parentbef7d299eb911086ea5a7ccf7a9da337e38a8491
bpo-38605: Make 'from __future__ import annotations' the default (GH-20434)

The hard part was making all the tests pass; there are some subtle issues here, because apparently the future import wasn't tested very thoroughly in previous Python versions.

For example, `inspect.signature()` returned type objects normally (except for forward references), but strings with the future import. We changed it to try and return type objects by calling `typing.get_type_hints()`, but fall back on returning strings if that function fails (which it may do if there are future references in the annotations that require passing in a specific namespace to resolve).
27 files changed:
Doc/reference/compound_stmts.rst
Doc/whatsnew/3.10.rst
Lib/dataclasses.py
Lib/inspect.py
Lib/test/dataclass_module_1.py
Lib/test/dataclass_module_1_str.py [deleted file]
Lib/test/dataclass_module_2.py
Lib/test/dataclass_module_2_str.py [deleted file]
Lib/test/dataclass_textanno.py
Lib/test/test_annotations.py [new file with mode: 0644]
Lib/test/test_coroutines.py
Lib/test/test_dataclasses.py
Lib/test/test_dis.py
Lib/test/test_functools.py
Lib/test/test_grammar.py
Lib/test/test_inspect.py
Lib/test/test_opcodes.py
Lib/test/test_positional_only_arg.py
Lib/test/test_pydoc.py
Lib/test/test_syntax.py
Lib/test/test_types.py
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Core and Builtins/2020-05-27-16-08-16.bpo-38605.rcs2uK.rst [new file with mode: 0644]
Python/ast_opt.c
Python/compile.c
Python/future.c