[issue42202] Optimize function annotation

Inada Naoki report at bugs.python.org
Tue Nov 17 19:50:23 EST 2020


Inada Naoki <songofacandy at gmail.com> added the comment:

I don't like co_annotations.

* It changes PyCode_NewXXX() API.

* Many functions don't have annotations. Adding annotation to code object makes code object fatter even if the function doesn't have annotation.

* Code object is immutable & hashable. Adding annotation to code object makes == and hash() complex.

* We may introduce lazy loading for docstring and annotation in the future.


func.__annotations__ =  ('x', 'int', 'z', 'float', 'return', 'Hoge') is much better because:

* Zero overhead for functions without any annotations.
* After annotation dict is created, the tuple can be released.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42202>
_______________________________________


More information about the Python-bugs-list mailing list