Special attributes added to classes on creation

Ian Kelly ian.g.kelly at gmail.com
Sun Jul 3 12:58:00 EDT 2016


On Sun, Jul 3, 2016 at 10:02 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> If I then try it against two identical (apart from their names) classes, I
> get these results:
>
>
> py> @process
> ... class K:
> ...     x = 1
> ...
> ['__dict__', '__doc__', '__module__', '__weakref__', 'x']
> py> class Q(metaclass=process):
> ...     x = 1
> ...
> ['__module__', '__qualname__', 'x']
> Now if I check the newly created Q, I see the same keys K has:
>
> py> sorted(Q.__dict__.keys())
> ['__dict__', '__doc__', '__module__', '__weakref__', 'x']
>
>
> Is there any documentation for exactly what keys are added to classes when?

I'm only aware of the sequence defined at
https://docs.python.org/3/reference/datamodel.html#customizing-class-creation.
Based on that, I'm surprised to even see __module__ and __qualname__
in there at the point when the metaclass is handling it.



More information about the Python-list mailing list