Skip to content

Commit 93a4456

Browse files
committed
Address review: fix/add links, document single-phase lookup key
1 parent 16b70db commit 93a4456

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

Doc/c-api/extension-modules.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ in the following ways:
323323
again.
324324
Instead, it creates a new module object with a new ``__dict__``, and copies
325325
the saved contents to it.
326+
Modules are matched to the saved contents by the module's full dotted
327+
name; the initialization function used is not taken into account.
328+
329+
As part of the first initialization, Python also adds the module to
330+
:data:`sys.modules` under its name.
326331
For example, given a single-phase module ``_testsinglephase``
327332
[#testsinglephase]_ that defines a function ``sum`` and an exception class
328333
``error``:

Doc/c-api/import.rst

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ Importing Modules
408408
409409
*spec* must be a :class:`~importlib.machinery.ModuleSpec` object.
410410
411-
*initfunc* must be an :ref:`initialization function <extension-export-hook>`,
411+
*initfunc* must be an :ref:`initialization function <extension-pyinit>`,
412412
the same as for :c:func:`PyImport_AppendInittab`.
413413
414414
On success, create and return a module object.
@@ -417,19 +417,16 @@ Importing Modules
417417
(Custom importers should do this in their
418418
:py:meth:`~importlib.abc.Loader.exec_module` method.)
419419
420-
If *initfunc* uses legacy single-phase initialization (that is, it
421-
creates the module with :c:func:`PyModule_Create`), the module is fully
422-
initialized by *initfunc* itself, and it is also added to
423-
:data:`sys.modules` under the spec's name, as is done for modules
424-
registered with :c:func:`PyImport_AppendInittab`.
420+
If *initfunc* uses
421+
:ref:`legacy single-phase initialization <single-phase-initialization>`,
422+
the module is fully initialized by *initfunc* itself, and it is also
423+
added to :data:`sys.modules` under the spec's name.
425424
Calling :c:func:`PyModule_Exec` on such a module is still safe.
426-
427-
The spec's name identifies the module for the purposes of the import
428-
system, in the same way as for built-in modules.
429-
If a single-phase init module was previously created under the same name
430-
(by this function, or in another interpreter), the existing module
431-
definition is reused and *initfunc* is not called, so a later call with
432-
the same name but a different *initfunc* has no effect.
425+
As with any single-phase module, the spec's name identifies the module:
426+
if a single-phase module was previously created under the same name
427+
(by this function, or in another interpreter), Python does not call
428+
*initfunc* again but reuses the saved module contents, so a later call
429+
with the same name but a different *initfunc* has no effect.
433430
434431
On error, return NULL with an exception set.
435432

0 commit comments

Comments
 (0)