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).
This commit is contained in:
Batuhan Taskaya 2020-10-06 23:03:02 +03:00 committed by GitHub
parent bef7d299eb
commit 044a1048ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 403 additions and 299 deletions

View file

@ -227,28 +227,26 @@ dis_annot_stmt_str = """\
2 0 SETUP_ANNOTATIONS
2 LOAD_CONST 0 (1)
4 STORE_NAME 0 (x)
6 LOAD_NAME 1 (int)
8 LOAD_NAME 2 (__annotations__)
10 LOAD_CONST 1 ('x')
6 LOAD_CONST 1 ('int')
8 LOAD_NAME 1 (__annotations__)
10 LOAD_CONST 2 ('x')
12 STORE_SUBSCR
3 14 LOAD_NAME 3 (fun)
16 LOAD_CONST 0 (1)
18 CALL_FUNCTION 1
20 LOAD_NAME 2 (__annotations__)
22 LOAD_CONST 2 ('y')
24 STORE_SUBSCR
3 14 LOAD_CONST 3 ('fun(1)')
16 LOAD_NAME 1 (__annotations__)
18 LOAD_CONST 4 ('y')
20 STORE_SUBSCR
4 26 LOAD_CONST 0 (1)
28 LOAD_NAME 4 (lst)
30 LOAD_NAME 3 (fun)
32 LOAD_CONST 3 (0)
34 CALL_FUNCTION 1
36 STORE_SUBSCR
38 LOAD_NAME 1 (int)
40 POP_TOP
42 LOAD_CONST 4 (None)
44 RETURN_VALUE
4 22 LOAD_CONST 0 (1)
24 LOAD_NAME 2 (lst)
26 LOAD_NAME 3 (fun)
28 LOAD_CONST 5 (0)
30 CALL_FUNCTION 1
32 STORE_SUBSCR
34 LOAD_NAME 4 (int)
36 POP_TOP
38 LOAD_CONST 6 (None)
40 RETURN_VALUE
"""
compound_stmt_str = """\