Class construction

Neil Cerutti neilc at norwich.edu
Tue Oct 22 11:48:46 EDT 2013


On 2013-10-21, Marcin Szamotulski <mszamot at gmail.com> wrote:
> So the process (with some simplifications) goes like this:
>
>     1. get metaclass: meta
>     2. call meta.__prepare__ to get namespace (class __dict__)
>     3. evaluate the class body in the namespace
>     4. call meta with arguemnts: name, bases, namespace
> 	(when you instantiate any class in Python, metaclass is just
> 	a class, first its __new__ method is called, and then its __init__) 
>
> All this is in builtin__build_class__.

In addition, the Python manual describes the process in detail.
See The Python Language Reference 8.7 Class definitions.

Here's a link to the 3.3 version of those docs:

http://docs.python.org/3.3/reference/compound_stmts.html#class-definitions

-- 
Neil Cerutti



More information about the Python-list mailing list