On 1/18/21 5:33 PM, Guido van Rossum wrote:
There's a secret though. `cls.__dict__` is not actually a dict -- is a mappingproxy. The proxy exists because we want to
be able to intercept changes to class attributes such as `__add__` or `__getattribute__` in order to manipulate the
C-level wrappers that implement such overloads.
So *perhaps* we could expand the mappingproxy class to trap read access to `__annotations__` as a key to do your
bidding. (The trick might be exposed by things like .keys() but that doesn't bother me as much.)
I honestly don't know how the mappingproxy and `__prepare__` interact.
`__prepare__` returns a dict-like namespace that is used as is. `EnumMeta` uses `__prepare__` to return an instance of
`_EnumDict`.
When `type.__new__` is called, whatever the namespace used to be is then converted into a normal Python dict, and a
mappingproxy is returned for all further `cls.__dict__` requests.
--
~Ethan~
_______________________________________________
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/4RO6ZBRBPXCR6R5OTYCJXCO7PZWDGNEK/
Code of Conduct: http://python.org/psf/codeofconduct/