Skip to content

Use multi-phase initialisation (PEP 489) #494

@AA-Turner

Description

@AA-Turner

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions