[docs] [issue26829] update docs: when creating classes a new dict is created for the final class object

R. David Murray report at bugs.python.org
Thu Jun 2 16:10:21 EDT 2016

R. David Murray added the comment:

Your suggested wording isn't correct, I'm afraid.  This subject is complex and somewhat obscure...I checked with Ethan to make sure my interpretation was correct.  The problem this issue is addressing is the fact that when type.__new__ is called (as in the metaclass example), whatever is passed in as the namespace has its *contents* copied into a new, standard python dict, and the original namespace object is discarded.  The metaclass example does this explicitly (by doing dict(namespace), but in fact type.__new__ does it implicitly (which IMO makes that example a bit confusing).

Also, that namespace is the only state.  The metaclass example obscures that by doing an attribute assignment after calling type.__new__, but that attribute assignment is actually updating the __dict__ of the new object ('result'), which is that new python dict containing the contents of namespace.

nosy: +r.david.murray

Python tracker <report at bugs.python.org>

More information about the docs mailing list