| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -320,6 +320,9 @@ ABC hierarchy:: | |||
| 320 | 320 | .. versionchanged:: 3.7 | |
| 321 | 321 | Introduced the optional :meth:`get_resource_reader` method. | |
| 322 | 322 | ||
| 323 | + .. versionchanged:: 3.15 | ||
| 324 | + Removed the ``load_module()`` method. | ||
| 325 | + | ||
| 323 | 326 | .. method:: create_module(spec) | |
| 324 | 327 | ||
| 325 | 328 | A method that returns the module object to use when | |
@@ -344,47 +347,6 @@ ABC hierarchy:: | |||
| 344 | 347 | .. versionchanged:: 3.6 | |
| 345 | 348 | :meth:`create_module` must also be defined. | |
| 346 | 349 | ||
| 347 | - .. method:: load_module(fullname) | ||
| 348 | - | ||
| 349 | - A legacy method for loading a module. If the module cannot be | ||
| 350 | - loaded, :exc:`ImportError` is raised, otherwise the loaded module is | ||
| 351 | - returned. | ||
| 352 | - | ||
| 353 | - If the requested module already exists in :data:`sys.modules`, that | ||
| 354 | - module should be used and reloaded. | ||
| 355 | - Otherwise the loader should create a new module and insert it into | ||
| 356 | - :data:`sys.modules` before any loading begins, to prevent recursion | ||
| 357 | - from the import. If the loader inserted a module and the load fails, it | ||
| 358 | - must be removed by the loader from :data:`sys.modules`; modules already | ||
| 359 | - in :data:`sys.modules` before the loader began execution should be left | ||
| 360 | - alone. | ||
| 361 | - | ||
| 362 | - The loader should set several attributes on the module | ||
| 363 | - (note that some of these attributes can change when a module is | ||
| 364 | - reloaded): | ||
| 365 | - | ||
| 366 | - - :attr:`module.__name__` | ||
| 367 | - - :attr:`module.__file__` | ||
| 368 | - - :attr:`module.__cached__` *(deprecated)* | ||
| 369 | - - :attr:`module.__path__` | ||
| 370 | - - :attr:`module.__package__` *(deprecated)* | ||
| 371 | - - :attr:`module.__loader__` *(deprecated)* | ||
| 372 | - | ||
| 373 | - When :meth:`exec_module` is available then backwards-compatible | ||
| 374 | - functionality is provided. | ||
| 375 | - | ||
| 376 | - .. versionchanged:: 3.4 | ||
| 377 | - Raise :exc:`ImportError` when called instead of | ||
| 378 | - :exc:`NotImplementedError`. Functionality provided when | ||
| 379 | - :meth:`exec_module` is available. | ||
| 380 | - | ||
| 381 | - .. deprecated-removed:: 3.4 3.15 | ||
| 382 | - The recommended API for loading a module is :meth:`exec_module` | ||
| 383 | - (and :meth:`create_module`). Loaders should implement it instead of | ||
| 384 | - :meth:`load_module`. The import machinery takes care of all the | ||
| 385 | - other responsibilities of :meth:`load_module` when | ||
| 386 | - :meth:`exec_module` is implemented. | ||
| 387 | - | ||
| 388 | 350 | ||
| 389 | 351 | .. class:: ResourceLoader | |
| 390 | 352 | ||
@@ -490,13 +452,6 @@ ABC hierarchy:: | |||
| 490 | 452 | ||
| 491 | 453 | .. versionadded:: 3.4 | |
| 492 | 454 | ||
| 493 | - .. method:: load_module(fullname) | ||
| 494 | - | ||
| 495 | - Implementation of :meth:`Loader.load_module`. | ||
| 496 | - | ||
| 497 | - .. deprecated-removed:: 3.4 3.15 | ||
| 498 | - use :meth:`exec_module` instead. | ||
| 499 | - | ||
| 500 | 455 | ||
| 501 | 456 | .. class:: ExecutionLoader | |
| 502 | 457 | ||
@@ -530,6 +485,9 @@ ABC hierarchy:: | |||
| 530 | 485 | ||
| 531 | 486 | .. versionadded:: 3.3 | |
| 532 | 487 | ||
| 488 | + .. versionchanged:: 3.15 | ||
| 489 | + Removed the ``load_module()`` method. | ||
| 490 | + | ||
| 533 | 491 | .. attribute:: name | |
| 534 | 492 | ||
| 535 | 493 | The name of the module the loader can handle. | |
@@ -538,13 +496,6 @@ ABC hierarchy:: | |||
| 538 | 496 | ||
| 539 | 497 | Path to the file of the module. | |
| 540 | 498 | ||
| 541 | - .. method:: load_module(fullname) | ||
| 542 | - | ||
| 543 | - Calls super's ``load_module()``. | ||
| 544 | - | ||
| 545 | - .. deprecated-removed:: 3.4 3.15 | ||
| 546 | - Use :meth:`Loader.exec_module` instead. | ||
| 547 | - | ||
| 548 | 499 | .. method:: get_filename(fullname) | |
| 549 | 500 | :abstractmethod: | |
| 550 | 501 | ||
@@ -576,6 +527,9 @@ ABC hierarchy:: | |||
| 576 | 527 | optimization to speed up loading by removing the parsing step of Python's | |
| 577 | 528 | compiler, and so no bytecode-specific API is exposed. | |
| 578 | 529 | ||
| 530 | + .. versionchanged:: 3.15 | ||
| 531 | + Removed the ``load_module()`` method. | ||
| 532 | + | ||
| 579 | 533 | .. method:: path_stats(path) | |
| 580 | 534 | ||
| 581 | 535 | Optional abstract method which returns a :class:`dict` containing | |
@@ -629,13 +583,6 @@ ABC hierarchy:: | |||
| 629 | 583 | ||
| 630 | 584 | .. versionadded:: 3.4 | |
| 631 | 585 | ||
| 632 | - .. method:: load_module(fullname) | ||
| 633 | - | ||
| 634 | - Concrete implementation of :meth:`Loader.load_module`. | ||
| 635 | - | ||
| 636 | - .. deprecated-removed:: 3.4 3.15 | ||
| 637 | - Use :meth:`exec_module` instead. | ||
| 638 | - | ||
| 639 | 586 | .. method:: get_source(fullname) | |
| 640 | 587 | ||
| 641 | 588 | Concrete implementation of :meth:`InspectLoader.get_source`. | |
@@ -1059,6 +1006,9 @@ find and load modules. | |||
| 1059 | 1006 | ||
| 1060 | 1007 | .. versionadded:: 3.3 | |
| 1061 | 1008 | ||
| 1009 | + .. versionchanged:: 3.15 | ||
| 1010 | + Removed the ``load_module()`` method. | ||
| 1011 | + | ||
| 1062 | 1012 | .. attribute:: name | |
| 1063 | 1013 | ||
| 1064 | 1014 | The name of the module that this loader will handle. | |
@@ -1079,15 +1029,6 @@ find and load modules. | |||
| 1079 | 1029 | ||
| 1080 | 1030 | Concrete implementation of :meth:`importlib.abc.SourceLoader.set_data`. | |
| 1081 | 1031 | ||
| 1082 | - .. method:: load_module(name=None) | ||
| 1083 | - | ||
| 1084 | - Concrete implementation of :meth:`importlib.abc.Loader.load_module` where | ||
| 1085 | - specifying the name of the module to load is optional. | ||
| 1086 | - | ||
| 1087 | - .. deprecated-removed:: 3.6 3.15 | ||
| 1088 | - | ||
| 1089 | - Use :meth:`importlib.abc.Loader.exec_module` instead. | ||
| 1090 | - | ||
| 1091 | 1032 | ||
| 1092 | 1033 | .. class:: SourcelessFileLoader(fullname, path) | |
| 1093 | 1034 | ||
@@ -1101,6 +1042,9 @@ find and load modules. | |||
| 1101 | 1042 | ||
| 1102 | 1043 | .. versionadded:: 3.3 | |
| 1103 | 1044 | ||
| 1045 | + .. versionchanged:: 3.15 | ||
| 1046 | + Removed the ``load_module()`` method. | ||
| 1047 | + | ||
| 1104 | 1048 | .. attribute:: name | |
| 1105 | 1049 | ||
| 1106 | 1050 | The name of the module the loader will handle. | |
@@ -1122,15 +1066,6 @@ find and load modules. | |||
| 1122 | 1066 | Returns ``None`` as bytecode files have no source when this loader is | |
| 1123 | 1067 | used. | |
| 1124 | 1068 | ||
| 1125 | - .. method:: load_module(name=None) | ||
| 1126 | - | ||
| 1127 | - Concrete implementation of :meth:`importlib.abc.Loader.load_module` where | ||
| 1128 | - specifying the name of the module to load is optional. | ||
| 1129 | - | ||
| 1130 | - .. deprecated-removed:: 3.6 3.15 | ||
| 1131 | - | ||
| 1132 | - Use :meth:`importlib.abc.Loader.exec_module` instead. | ||
| 1133 | - | ||
| 1134 | 1069 | ||
| 1135 | 1070 | .. class:: ExtensionFileLoader(fullname, path) | |
| 1136 | 1071 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -359,21 +359,16 @@ of what happens during the loading portion of import:: | |||
| 359 | 359 | if spec.loader is None: | |
| 360 | 360 | # unsupported | |
| 361 | 361 | raise ImportError | |
| 362 | - if spec.origin is None and spec.submodule_search_locations is not None: | ||
| 363 | - # namespace package | ||
| 364 | - sys.modules[spec.name] = module | ||
| 365 | - elif not hasattr(spec.loader, 'exec_module'): | ||
| 366 | - module = spec.loader.load_module(spec.name) | ||
| 367 | - else: | ||
| 368 | - sys.modules[spec.name] = module | ||
| 362 | + | ||
| 363 | + sys.modules[spec.name] = module | ||
| 364 | + try: | ||
| 365 | + spec.loader.exec_module(module) | ||
| 366 | + except BaseException: | ||
| 369 | 367 | try: | |
| 370 | - spec.loader.exec_module(module) | ||
| 371 | - except BaseException: | ||
| 372 | - try: | ||
| 373 | - del sys.modules[spec.name] | ||
| 374 | - except KeyError: | ||
| 375 | - pass | ||
| 376 | - raise | ||
| 368 | + del sys.modules[spec.name] | ||
| 369 | + except KeyError: | ||
| 370 | + pass | ||
| 371 | + raise | ||
| 377 | 372 | return sys.modules[spec.name] | |
| 378 | 373 | ||
| 379 | 374 | Note the following details: | |
@@ -408,7 +403,10 @@ Note the following details: | |||
| 408 | 403 | .. versionchanged:: 3.4 | |
| 409 | 404 | The import system has taken over the boilerplate responsibilities of | |
| 410 | 405 | loaders. These were previously performed by the | |
| 411 | - :meth:`importlib.abc.Loader.load_module` method. | ||
| 406 | + ``importlib.abc.Loader.load_module`` method. | ||
| 407 | + | ||
| 408 | + .. versionchanged:: 3.15 | ||
| 409 | + The ``load_module`` method is no longer used. | ||
| 412 | 410 | ||
| 413 | 411 | Loaders | |
| 414 | 412 | ------- | |
@@ -443,7 +441,7 @@ import machinery will create the new module itself. | |||
| 443 | 441 | The :meth:`~importlib.abc.Loader.create_module` method of loaders. | |
| 444 | 442 | ||
| 445 | 443 | .. versionchanged:: 3.4 | |
| 446 | - The :meth:`~importlib.abc.Loader.load_module` method was replaced by | ||
| 444 | + The ``importlib.abc.Loader.load_module`` method was replaced by | ||
| 447 | 445 | :meth:`~importlib.abc.Loader.exec_module` and the import | |
| 448 | 446 | machinery assumed all the boilerplate responsibilities of loading. | |
| 449 | 447 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1622,7 +1622,7 @@ Deprecated | |||
| 1622 | 1622 | compatibility. Specifically, | |
| 1623 | 1623 | :meth:`!find_loader`/:meth:`!find_module` | |
| 1624 | 1624 | (superseded by :meth:`~importlib.abc.MetaPathFinder.find_spec`), | |
| 1625 | - :meth:`~importlib.abc.Loader.load_module` | ||
| 1625 | + ``importlib.abc.Loader.load_module`` | ||
| 1626 | 1626 | (superseded by :meth:`~importlib.abc.Loader.exec_module`), | |
| 1627 | 1627 | :meth:`!module_repr` (which the import system | |
| 1628 | 1628 | takes care of for you), the ``__package__`` attribute | |
@@ -1652,7 +1652,7 @@ Deprecated | |||
| 1652 | 1652 | preference for :meth:`~zipimport.zipimporter.exec_module`. | |
| 1653 | 1653 | (Contributed by Brett Cannon in :issue:`26131`.) | |
| 1654 | 1654 | ||
| 1655 | - * The use of :meth:`~importlib.abc.Loader.load_module` by the import | ||
| 1655 | + * The use of ``importlib.abc.Loader.load_module`` by the import | ||
| 1656 | 1656 | system now triggers an :exc:`ImportWarning` as | |
| 1657 | 1657 | :meth:`~importlib.abc.Loader.exec_module` is preferred. | |
| 1658 | 1658 | (Contributed by Brett Cannon in :issue:`26131`.) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2086,10 +2086,10 @@ Deprecations in the Python API | |||
| 2086 | 2086 | :meth:`!importlib.abc.PathEntryFinder.find_loader` and | |
| 2087 | 2087 | :meth:`!find_module` are replaced by | |
| 2088 | 2088 | :meth:`importlib.abc.PathEntryFinder.find_spec`; all of the :samp:`{xxx}Loader` ABC | |
| 2089 | - ``load_module`` methods (:meth:`!importlib.abc.Loader.load_module`, | ||
| 2090 | - :meth:`!importlib.abc.InspectLoader.load_module`, | ||
| 2091 | - :meth:`!importlib.abc.FileLoader.load_module`, | ||
| 2092 | - :meth:`!importlib.abc.SourceLoader.load_module`) should no longer be | ||
| 2089 | + ``load_module`` methods (``importlib.abc.Loader.load_module``, | ||
| 2090 | + ``importlib.abc.InspectLoader.load_module``, | ||
| 2091 | + ``importlib.abc.FileLoader.load_module``, | ||
| 2092 | + ``importlib.abc.SourceLoader.load_module``) should no longer be | ||
| 2093 | 2093 | implemented, instead loaders should implement an | |
| 2094 | 2094 | ``exec_module`` method | |
| 2095 | 2095 | (:meth:`importlib.abc.Loader.exec_module`, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2006,10 +2006,10 @@ deprecated. | |||
| 2006 | 2006 | importlib | |
| 2007 | 2007 | ~~~~~~~~~ | |
| 2008 | 2008 | ||
| 2009 | - The :meth:`importlib.machinery.SourceFileLoader.load_module` and | ||
| 2010 | - :meth:`importlib.machinery.SourcelessFileLoader.load_module` methods | ||
| 2009 | + The ``importlib.machinery.SourceFileLoader.load_module`` and | ||
| 2010 | + ``importlib.machinery.SourcelessFileLoader.load_module`` methods | ||
| 2011 | 2011 | are now deprecated. They were the only remaining implementations of | |
| 2012 | - :meth:`importlib.abc.Loader.load_module` in :mod:`importlib` that had not | ||
| 2012 | + ``importlib.abc.Loader.load_module`` in :mod:`importlib` that had not | ||
| 2013 | 2013 | been deprecated in previous versions of Python in favour of | |
| 2014 | 2014 | :meth:`importlib.abc.Loader.exec_module`. | |
| 2015 | 2015 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,21 +19,3 @@ def create_module(self, spec): | |||
| 19 | 19 | ||
| 20 | 20 | # We don't define exec_module() here since that would break | |
| 21 | 21 | # hasattr checks we do to support backward compatibility. | |
| 22 | - | ||
| 23 | - def load_module(self, fullname): | ||
| 24 | - """Return the loaded module. | ||
| 25 | - | ||
| 26 | - The module must be added to sys.modules and have import-related | ||
| 27 | - attributes set properly. The fullname is a str. | ||
| 28 | - | ||
| 29 | - ImportError is raised on failure. | ||
| 30 | - | ||
| 31 | - This method is deprecated in favor of loader.exec_module(). If | ||
| 32 | - exec_module() exists then it is used to provide a backwards-compatible | ||
| 33 | - functionality for this method. | ||
| 34 | - | ||
| 35 | - """ | ||
| 36 | - if not hasattr(self, 'exec_module'): | ||
| 37 | - raise ImportError | ||
| 38 | - # Warning implemented in _load_module_shim(). | ||
| 39 | - return _bootstrap._load_module_shim(self, fullname) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments