diff options
author | Yurii Karabas <1998uriyyo@gmail.com> | 2020-11-25 10:43:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-25 10:43:18 (GMT) |
commit | 7301979b23406220510dd2c7934a21b41b647119 (patch) | |
tree | 296b337317ac71d34001c17f4b4b7bea918cbf6f /Lib/importlib | |
parent | 85c84920f511d0d73a133336daeaf715a022cd64 (diff) | |
download | cpython-7301979b23406220510dd2c7934a21b41b647119.zip cpython-7301979b23406220510dd2c7934a21b41b647119.tar.gz cpython-7301979b23406220510dd2c7934a21b41b647119.tar.bz2 |
bpo-42202: Store func annotations as a tuple (GH-23316)
Reduce memory footprint and improve performance of loading modules having many func annotations.
>>> sys.getsizeof({"a":"int","b":"int","return":"int"})
232
>>> sys.getsizeof(("a","int","b","int","return","int"))
88
The tuple is converted into dict on the fly when `func.__annotations__` is accessed first.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
Diffstat (limited to 'Lib/importlib')
-rw-r--r-- | Lib/importlib/_bootstrap_external.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 0ae49cf..b8dd128 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -311,6 +311,7 @@ _code_type = type(_write_atomic.__code__) # Python 3.9a2 3425 (simplify bytecodes for **value unpacking) # Python 3.10a1 3430 (Make 'annotations' future by default) # Python 3.10a1 3431 (New line number table format -- PEP 626) +# Python 3.10a2 3432 (Function annotation for MAKE_FUNCTION is changed from dict to tuple bpo-42202) # # MAGIC must change whenever the bytecode emitted by the compiler may no @@ -320,7 +321,7 @@ _code_type = type(_write_atomic.__code__) # Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array # in PC/launcher.c must also be updated. -MAGIC_NUMBER = (3431).to_bytes(2, 'little') + b'\r\n' +MAGIC_NUMBER = (3432).to_bytes(2, 'little') + b'\r\n' _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c _PYCACHE = '__pycache__' |