@@ -375,32 +375,32 @@ of what happens during the loading portion of import::
375
375
376
376
Note the following details:
377
377
378
- * If there is an existing module object with the given name in
379
- :data: `sys.modules `, import will have already returned it.
378
+ * If there is an existing module object with the given name in
379
+ :data: `sys.modules `, import will have already returned it.
380
380
381
- * The module will exist in :data: `sys.modules ` before the loader
382
- executes the module code. This is crucial because the module code may
383
- (directly or indirectly) import itself; adding it to :data: `sys.modules `
384
- beforehand prevents unbounded recursion in the worst case and multiple
385
- loading in the best.
381
+ * The module will exist in :data: `sys.modules ` before the loader
382
+ executes the module code. This is crucial because the module code may
383
+ (directly or indirectly) import itself; adding it to :data: `sys.modules `
384
+ beforehand prevents unbounded recursion in the worst case and multiple
385
+ loading in the best.
386
386
387
- * If loading fails, the failing module -- and only the failing module --
388
- gets removed from :data: `sys.modules `. Any module already in the
389
- :data: `sys.modules ` cache, and any module that was successfully loaded
390
- as a side-effect, must remain in the cache. This contrasts with
391
- reloading where even the failing module is left in :data: `sys.modules `.
387
+ * If loading fails, the failing module -- and only the failing module --
388
+ gets removed from :data: `sys.modules `. Any module already in the
389
+ :data: `sys.modules ` cache, and any module that was successfully loaded
390
+ as a side-effect, must remain in the cache. This contrasts with
391
+ reloading where even the failing module is left in :data: `sys.modules `.
392
392
393
- * After the module is created but before execution, the import machinery
394
- sets the import-related module attributes ("_init_module_attrs" in
395
- the pseudo-code example above), as summarized in a
396
- :ref: `later section <import-mod-attrs >`.
393
+ * After the module is created but before execution, the import machinery
394
+ sets the import-related module attributes ("_init_module_attrs" in
395
+ the pseudo-code example above), as summarized in a
396
+ :ref: `later section <import-mod-attrs >`.
397
397
398
- * Module execution is the key moment of loading in which the module's
399
- namespace gets populated. Execution is entirely delegated to the
400
- loader, which gets to decide what gets populated and how.
398
+ * Module execution is the key moment of loading in which the module's
399
+ namespace gets populated. Execution is entirely delegated to the
400
+ loader, which gets to decide what gets populated and how.
401
401
402
- * The module created during loading and passed to exec_module() may
403
- not be the one returned at the end of import [#fnlo ]_.
402
+ * The module created during loading and passed to exec_module() may
403
+ not be the one returned at the end of import [#fnlo ]_.
404
404
405
405
.. versionchanged :: 3.4
406
406
The import system has taken over the boilerplate responsibilities of
@@ -417,13 +417,13 @@ returned from :meth:`~importlib.abc.Loader.exec_module` is ignored.
417
417
418
418
Loaders must satisfy the following requirements:
419
419
420
- * If the module is a Python module (as opposed to a built-in module or a
421
- dynamically loaded extension), the loader should execute the module's code
422
- in the module's global name space (``module.__dict__ ``).
420
+ * If the module is a Python module (as opposed to a built-in module or a
421
+ dynamically loaded extension), the loader should execute the module's code
422
+ in the module's global name space (``module.__dict__ ``).
423
423
424
- * If the loader cannot execute the module, it should raise an
425
- :exc: `ImportError `, although any other exception raised during
426
- :meth: `~importlib.abc.Loader.exec_module ` will be propagated.
424
+ * If the loader cannot execute the module, it should raise an
425
+ :exc: `ImportError `, although any other exception raised during
426
+ :meth: `~importlib.abc.Loader.exec_module ` will be propagated.
427
427
428
428
In many cases, the finder and loader can be the same object; in such cases the
429
429
:meth: `~importlib.abc.MetaPathFinder.find_spec ` method would just return a
@@ -453,20 +453,20 @@ import machinery will create the new module itself.
453
453
functionality described above in addition to executing the module. All
454
454
the same constraints apply, with some additional clarification:
455
455
456
- * If there is an existing module object with the given name in
457
- :data: `sys.modules `, the loader must use that existing module.
458
- (Otherwise, :func: `importlib.reload ` will not work correctly.) If the
459
- named module does not exist in :data: `sys.modules `, the loader
460
- must create a new module object and add it to :data: `sys.modules `.
456
+ * If there is an existing module object with the given name in
457
+ :data: `sys.modules `, the loader must use that existing module.
458
+ (Otherwise, :func: `importlib.reload ` will not work correctly.) If the
459
+ named module does not exist in :data: `sys.modules `, the loader
460
+ must create a new module object and add it to :data: `sys.modules `.
461
461
462
- * The module *must * exist in :data: `sys.modules ` before the loader
463
- executes the module code, to prevent unbounded recursion or multiple
464
- loading.
462
+ * The module *must * exist in :data: `sys.modules ` before the loader
463
+ executes the module code, to prevent unbounded recursion or multiple
464
+ loading.
465
465
466
- * If loading fails, the loader must remove any modules it has inserted
467
- into :data: `sys.modules `, but it must remove **only ** the failing
468
- module(s), and only if the loader itself has loaded the module(s)
469
- explicitly.
466
+ * If loading fails, the loader must remove any modules it has inserted
467
+ into :data: `sys.modules `, but it must remove **only ** the failing
468
+ module(s), and only if the loader itself has loaded the module(s)
469
+ explicitly.
470
470
471
471
.. versionchanged :: 3.5
472
472
A :exc: `DeprecationWarning ` is raised when ``exec_module() `` is defined but
@@ -693,17 +693,17 @@ with defaults for whatever information is missing.
693
693
694
694
Here are the exact rules used:
695
695
696
- * If the module has a ``__spec__ `` attribute, the information in the spec
697
- is used to generate the repr. The "name", "loader", "origin", and
698
- "has_location" attributes are consulted.
696
+ * If the module has a ``__spec__ `` attribute, the information in the spec
697
+ is used to generate the repr. The "name", "loader", "origin", and
698
+ "has_location" attributes are consulted.
699
699
700
- * If the module has a ``__file__ `` attribute, this is used as part of the
701
- module's repr.
700
+ * If the module has a ``__file__ `` attribute, this is used as part of the
701
+ module's repr.
702
702
703
- * If the module has no ``__file__ `` but does have a ``__loader__ `` that is not
704
- ``None ``, then the loader's repr is used as part of the module's repr.
703
+ * If the module has no ``__file__ `` but does have a ``__loader__ `` that is not
704
+ ``None ``, then the loader's repr is used as part of the module's repr.
705
705
706
- * Otherwise, just use the module's ``__name__ `` in the repr.
706
+ * Otherwise, just use the module's ``__name__ `` in the repr.
707
707
708
708
.. versionchanged :: 3.12
709
709
Use of :meth: `!module_repr `, having been deprecated since Python 3.4, was
0 commit comments