Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111006

Re: Special attributes added to classes on creation

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Special attributes added to classes on creation
Date 2016-07-03 10:58 -0600
Message-ID <mailman.43.1467565121.2295.python-list@python.org> (permalink)
References <57793711$0$1611$c3e8da3$5496439d@news.astraweb.com> <CALwzidnMjSBoGakPoewZKtMh7-aT6CWcPB9iQGKoV9gexk=kYA@mail.gmail.com>

Show all headers | View raw


On Sun, Jul 3, 2016 at 10:02 AM, Steven D'Aprano <steve@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Special attributes added to classes on creation Steven D'Aprano <steve@pearwood.info> - 2016-07-04 02:02 +1000
  Re: Special attributes added to classes on creation Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-03 10:58 -0600
  Re: Special attributes added to classes on creation eryk sun <eryksun@gmail.com> - 2016-07-03 23:07 +0000
  Re: Special attributes added to classes on creation Xiang Zhang <zhangyangyu0614@gmail.com> - 2016-07-04 03:22 -0700

csiph-web