Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Use multi-phase initialisation (PEP 489)

Open AA-Turner opened this issue 6 months ago • 1 comments

Hello,

Please consider adopting multi-phase init for your Python extension modules. In short, multi-phase makes extension modules behave more like pure-Python modules and means that the import system can determine what a capabilities a module has before executing it.

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.

It is the preferred mechanism for extension module initialisation, and there is a proposal to deprecate single phase init.

Thanks, Adam

AA-Turner avatar May 28 '25 08:05 AA-Turner

Hi. I've created #8983. Let me know if you think I've missed anything.

radarhere avatar May 28 '25 13:05 radarhere