Message266512
In general the patch LGTM, besides few minor comments.
But new implementation uses longer bytecode for annotations. Current code packs argument names in one constant tuple:
$ ./python -m dis
def f(x: int, y: str, z: float): pass
1 0 LOAD_NAME 0 (int)
2 LOAD_NAME 1 (str)
4 LOAD_NAME 2 (float)
6 LOAD_CONST 0 (('x', 'y', 'z'))
8 LOAD_CONST 1 (<code object f at 0xb6fc1640, file "<stdin>", line 1>)
10 LOAD_CONST 2 ('f')
12 EXTENDED_ARG 4
14 EXTENDED_ARG 1024
16 MAKE_FUNCTION 262144
18 STORE_NAME 3 (f)
20 LOAD_CONST 3 (None)
22 RETURN_VALUE
New code uses LOAD_CONST for every name:
$ ./python -m dis
def f(x: int, y: str, z: float): pass
1 0 LOAD_CONST 0 ('x')
2 LOAD_NAME 0 (int)
4 LOAD_CONST 1 ('y')
6 LOAD_NAME 1 (str)
8 LOAD_CONST 2 ('z')
10 LOAD_NAME 2 (float)
12 BUILD_MAP 3
14 LOAD_CONST 3 (<code object f at 0xb7035a20, file "<stdin>", line 1>)
16 LOAD_CONST 4 ('f')
18 MAKE_FUNCTION 4
20 STORE_NAME 3 (f)
22 LOAD_CONST 5 (None)
24 RETURN_VALUE
With new opcode that creates a dict from values and a tuple of keys (issue27140) new code would be only one instruction longer. |
|
Date |
User |
Action |
Args |
2016-05-27 20:44:22 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, Demur Rumed |
2016-05-27 20:44:22 | serhiy.storchaka | set | messageid: <1464381862.41.0.0958175392432.issue27095@psf.upfronthosting.co.za> |
2016-05-27 20:44:22 | serhiy.storchaka | link | issue27095 messages |
2016-05-27 20:44:21 | serhiy.storchaka | create | |
|