June 2017
Beginner to intermediate
274 pages
6h 49m
English
There's a reason why I keep saying while the code is being evaluated. After __prepare__ is called, the code inside the class block is run and it uses the dictionary that was returned from __prepare__ as its namespace, as shown here:

However, after that, the metaclass's __new__ method is called. One of the things __new__ needs to do is call type.__new__ to actually allocate and initialize a chunk of memory to contain the class data, and one of the things type.__new__ does is convert whatever we pass as a namespace for the object into a normal dict.
This means that if we want to retain special information that our namespace ...
Read now
Unlock full access