[issue37949] Create empty __annotations__ dictionaries lazily

Raymond Hettinger report at bugs.python.org
Mon Aug 26 02:39:48 EDT 2019


New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:

Right now, every heap function is given a new annotations dictionary even if annotations aren't used.  How about we create these lazily in order to speed-up function creation time, improve start-up time, and save space.


>>> def f(): pass

>>> def g(): return 1

>>> f.__annotations__
{}
>>> g.__annotations__
{}
>>> hex(id(f.__annotations__))
'0x109207e40'
>>> hex(id(g.__annotations__))
'0x1092296c0'

----------
components: Interpreter Core
messages: 350490
nosy: rhettinger
priority: low
severity: normal
status: open
title: Create empty __annotations__ dictionaries lazily
type: performance
versions: Python 3.9

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


More information about the Python-bugs-list mailing list