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