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~