2

I am reading cpython source code class implementation, I knew the basic process of class definition and creation:

Class definition:

LOAD_BUILD_CLASS -> builtin___build_class__ -> meta -> type_call -> type_new

Class creation:

type_call -> type_new

And I knew the user defined functions are stored in the namespace and finally in the tp_dict of that type.

My question: User defined __init__ function is stored in the type->tp_dict, when python initializes a type it calls type->tp_init function. I can not find where in cpython source code the user defined __init__ function is called when initializing a class.

1 Answer 1

1

Find the result by myself, type_new will call PyType_Ready and fixup_slot_dispatchers, in later function user defined function will be handled in slots.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.