On 1/11/21 6:09 PM, Chris Angelico wrote:
On Tue, Jan 12, 2021 at 12:56 PM Larry Hastings <la...@hastings.org> wrote:
It was a balancing act. Using an 64-byte empty dict per object with no defined
annotations seems so wasteful. And anything short of an empty dict, you'd have to guard
against. Current code already has to guard against "__annotations__ aren't
set" anyway, so I figured the cost of migrating to checking a different condition
would be small. And None is so cheap, and the guard is so easy:
if o.__annotations__:
Does it have to be mutable? If not, maybe there could be a singleton
"immutable empty dict-like object", in the same way that an empty
tuple can be put anywhere that expects a sequence. That'd be as cheap
as None (modulo a once-per-interpreter cost for the additional static
object).
Historically, annotations dicts are mutable. I don't know how often
people mutate them, but I would assume it's uncommon. So technically
this would be a breaking change. But it does seem low-risk.
Cheers,
//arry/
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/DOCTVXVFOKTO445YPVPMNJ6KXWXNV3LJ/
Code of Conduct: http://python.org/psf/codeofconduct/