-
-
Notifications
You must be signed in to change notification settings - Fork 171
Description
Multi-phase initialisation was introduced in PEP 489 for Python 3.5. It replaces the previous 'single-phase' mechanism by splitting the module creation process into creation and execution phases. Quoting from the documentation:
Extension modules created this way behave more like Python modules: the initialization is split between the creation phase, when the module object is created, and the execution phase, when it is populated. The distinction is similar to the
__new__()and__init__()methods of classes.
This means that Python can determine the capabilities a module supports before executing it. It is a more flexible approach, and has been recommended for several years. This is of particular interest to me as MarkupSafe is one of the few extension modules in Sphinx's dependency tree, and currently prevents using subinterpreters with Sphinx.
You may have already seen that there is a proposal to deprecate single-phase init
, though this would currently be documentation-only.
A