This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author methane
Recipients methane
Date 2020-10-30.06:47:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1604040435.44.0.369975398522.issue42202@roundup.psfhosted.org>
In-reply-to
Content
Look this example:

code:

```
# code
def foo(x: int, /, y, *, z: float) -> Hoge:
    pass

# dis
 2          12 LOAD_CONST               2 ('int')
            14 LOAD_CONST               3 ('float')
            16 LOAD_CONST               4 ('Hoge')
            18 LOAD_CONST               5 (('x', 'z', 'return'))
            20 BUILD_CONST_KEY_MAP      3
            22 LOAD_CONST               6 (<code object foo at ...>)
            24 LOAD_CONST               7 ('foo')
            26 MAKE_FUNCTION            4 (annotations)
            28 STORE_NAME               2 (foo) 
```

Four `LOAD_CONST` and `BUILD_CONST_KEY_MAP` are used to generate annotation dict. This makes program load slow and eat more memory.

Annotation information can be stored in some compact form. And creating annotation dict can be postponed to when `func.__annotation__` is accessed.

Ideas for the compact form:

1. Tuple.
   In above example, `('int', None, 'float', 'Hoge')` can be used. None means no annotation for the 'y' parameter.

2. Serialize into str or bytes.
   JSON like format can be used, like `x:int,z:float;Hoge`. Compact. But the string/bytes has lower chance to be shared with other constants in same module.
History
Date User Action Args
2020-10-30 06:47:15methanesetrecipients: + methane
2020-10-30 06:47:15methanesetmessageid: <1604040435.44.0.369975398522.issue42202@roundup.psfhosted.org>
2020-10-30 06:47:15methanelinkissue42202 messages
2020-10-30 06:47:14methanecreate