| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bcea36f commit 3269978
39 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,28 +127,6 @@ Functions | |||
| 127 | 127 | .. versionchanged:: 3.3 | |
| 128 | 128 | Parent packages are automatically imported. | |
| 129 | 129 | ||
| 130 | - .. function:: find_loader(name, path=None) | ||
| 131 | - | ||
| 132 | - Find the loader for a module, optionally within the specified *path*. If the | ||
| 133 | - module is in :attr:`sys.modules`, then ``sys.modules[name].__loader__`` is | ||
| 134 | - returned (unless the loader would be ``None`` or is not set, in which case | ||
| 135 | - :exc:`ValueError` is raised). Otherwise a search using :attr:`sys.meta_path` | ||
| 136 | - is done. ``None`` is returned if no loader is found. | ||
| 137 | - | ||
| 138 | - A dotted name does not have its parents implicitly imported as that requires | ||
| 139 | - loading them and that may not be desired. To properly import a submodule you | ||
| 140 | - will need to import all parent packages of the submodule and use the correct | ||
| 141 | - argument to *path*. | ||
| 142 | - | ||
| 143 | - .. versionadded:: 3.3 | ||
| 144 | - | ||
| 145 | - .. versionchanged:: 3.4 | ||
| 146 | - If ``__loader__`` is not set, raise :exc:`ValueError`, just like when the | ||
| 147 | - attribute is set to ``None``. | ||
| 148 | - | ||
| 149 | - .. deprecated:: 3.4 | ||
| 150 | - Use :func:`importlib.util.find_spec` instead. | ||
| 151 | - | ||
| 152 | 130 | .. function:: invalidate_caches() | |
| 153 | 131 | ||
| 154 | 132 | Invalidate the internal caches of finders stored at | |
@@ -247,7 +225,6 @@ are also provided to help in implementing the core ABCs. | |||
| 247 | 225 | ABC hierarchy:: | |
| 248 | 226 | ||
| 249 | 227 | object | |
| 250 | - +-- Finder (deprecated) | ||
| 251 | 228 | +-- MetaPathFinder | |
| 252 | 229 | +-- PathEntryFinder | |
| 253 | 230 | +-- Loader | |
@@ -258,36 +235,14 @@ ABC hierarchy:: | |||
| 258 | 235 | +-- SourceLoader | |
| 259 | 236 | ||
| 260 | 237 | ||
| 261 | - .. class:: Finder | ||
| 262 | - | ||
| 263 | - An abstract base class representing a :term:`finder`. | ||
| 264 | - | ||
| 265 | - .. deprecated:: 3.3 | ||
| 266 | - Use :class:`MetaPathFinder` or :class:`PathEntryFinder` instead. | ||
| 267 | - | ||
| 268 | - .. abstractmethod:: find_module(fullname, path=None) | ||
| 269 | - | ||
| 270 | - An abstract method for finding a :term:`loader` for the specified | ||
| 271 | - module. Originally specified in :pep:`302`, this method was meant | ||
| 272 | - for use in :data:`sys.meta_path` and in the path-based import subsystem. | ||
| 273 | - | ||
| 274 | - .. versionchanged:: 3.4 | ||
| 275 | - Returns ``None`` when called instead of raising | ||
| 276 | - :exc:`NotImplementedError`. | ||
| 277 | - | ||
| 278 | - .. deprecated:: 3.10 | ||
| 279 | - Implement :meth:`MetaPathFinder.find_spec` or | ||
| 280 | - :meth:`PathEntryFinder.find_spec` instead. | ||
| 281 | - | ||
| 282 | - | ||
| 283 | 238 | .. class:: MetaPathFinder | |
| 284 | 239 | ||
| 285 | 240 | An abstract base class representing a :term:`meta path finder`. | |
| 286 | 241 | ||
| 287 | 242 | .. versionadded:: 3.3 | |
| 288 | 243 | ||
| 289 | 244 | .. versionchanged:: 3.10 | |
| 290 | - No longer a subclass of :class:`Finder`. | ||
| 245 | + No longer a subclass of :class:`!Finder`. | ||
| 291 | 246 | ||
| 292 | 247 | .. method:: find_spec(fullname, path, target=None) | |
| 293 | 248 | ||
@@ -303,25 +258,6 @@ ABC hierarchy:: | |||
| 303 | 258 | ||
| 304 | 259 | .. versionadded:: 3.4 | |
| 305 | 260 | ||
| 306 | - .. method:: find_module(fullname, path) | ||
| 307 | - | ||
| 308 | - A legacy method for finding a :term:`loader` for the specified | ||
| 309 | - module. If this is a top-level import, *path* will be ``None``. | ||
| 310 | - Otherwise, this is a search for a subpackage or module and *path* | ||
| 311 | - will be the value of :attr:`__path__` from the parent | ||
| 312 | - package. If a loader cannot be found, ``None`` is returned. | ||
| 313 | - | ||
| 314 | - If :meth:`find_spec` is defined, backwards-compatible functionality is | ||
| 315 | - provided. | ||
| 316 | - | ||
| 317 | - .. versionchanged:: 3.4 | ||
| 318 | - Returns ``None`` when called instead of raising | ||
| 319 | - :exc:`NotImplementedError`. Can use :meth:`find_spec` to provide | ||
| 320 | - functionality. | ||
| 321 | - | ||
| 322 | - .. deprecated:: 3.4 | ||
| 323 | - Use :meth:`find_spec` instead. | ||
| 324 | - | ||
| 325 | 261 | .. method:: invalidate_caches() | |
| 326 | 262 | ||
| 327 | 263 | An optional method which, when called, should invalidate any internal | |
@@ -342,7 +278,7 @@ ABC hierarchy:: | |||
| 342 | 278 | .. versionadded:: 3.3 | |
| 343 | 279 | ||
| 344 | 280 | .. versionchanged:: 3.10 | |
| 345 | - No longer a subclass of :class:`Finder`. | ||
| 281 | + No longer a subclass of :class:`!Finder`. | ||
| 346 | 282 | ||
| 347 | 283 | .. method:: find_spec(fullname, target=None) | |
| 348 | 284 | ||
@@ -356,36 +292,6 @@ ABC hierarchy:: | |||
| 356 | 292 | ||
| 357 | 293 | .. versionadded:: 3.4 | |
| 358 | 294 | ||
| 359 | - .. method:: find_loader(fullname) | ||
| 360 | - | ||
| 361 | - A legacy method for finding a :term:`loader` for the specified | ||
| 362 | - module. Returns a 2-tuple of ``(loader, portion)`` where ``portion`` | ||
| 363 | - is a sequence of file system locations contributing to part of a namespace | ||
| 364 | - package. The loader may be ``None`` while specifying ``portion`` to | ||
| 365 | - signify the contribution of the file system locations to a namespace | ||
| 366 | - package. An empty list can be used for ``portion`` to signify the loader | ||
| 367 | - is not part of a namespace package. If ``loader`` is ``None`` and | ||
| 368 | - ``portion`` is the empty list then no loader or location for a namespace | ||
| 369 | - package were found (i.e. failure to find anything for the module). | ||
| 370 | - | ||
| 371 | - If :meth:`find_spec` is defined then backwards-compatible functionality is | ||
| 372 | - provided. | ||
| 373 | - | ||
| 374 | - .. versionchanged:: 3.4 | ||
| 375 | - Returns ``(None, [])`` instead of raising :exc:`NotImplementedError`. | ||
| 376 | - Uses :meth:`find_spec` when available to provide functionality. | ||
| 377 | - | ||
| 378 | - .. deprecated:: 3.4 | ||
| 379 | - Use :meth:`find_spec` instead. | ||
| 380 | - | ||
| 381 | - .. method:: find_module(fullname) | ||
| 382 | - | ||
| 383 | - A concrete implementation of :meth:`Finder.find_module` which is | ||
| 384 | - equivalent to ``self.find_loader(fullname)[0]``. | ||
| 385 | - | ||
| 386 | - .. deprecated:: 3.4 | ||
| 387 | - Use :meth:`find_spec` instead. | ||
| 388 | - | ||
| 389 | 295 | .. method:: invalidate_caches() | |
| 390 | 296 | ||
| 391 | 297 | An optional method which, when called, should invalidate any internal | |
@@ -881,13 +787,6 @@ find and load modules. | |||
| 881 | 787 | is no longer valid then ``None`` is returned but no value is cached | |
| 882 | 788 | in :data:`sys.path_importer_cache`. | |
| 883 | 789 | ||
| 884 | - .. classmethod:: find_module(fullname, path=None) | ||
| 885 | - | ||
| 886 | - A legacy wrapper around :meth:`find_spec`. | ||
| 887 | - | ||
| 888 | - .. deprecated:: 3.4 | ||
| 889 | - Use :meth:`find_spec` instead. | ||
| 890 | - | ||
| 891 | 790 | .. classmethod:: invalidate_caches() | |
| 892 | 791 | ||
| 893 | 792 | Calls :meth:`importlib.abc.PathEntryFinder.invalidate_caches` on all | |
@@ -938,13 +837,6 @@ find and load modules. | |||
| 938 | 837 | ||
| 939 | 838 | .. versionadded:: 3.4 | |
| 940 | 839 | ||
| 941 | - .. method:: find_loader(fullname) | ||
| 942 | - | ||
| 943 | - Attempt to find the loader to handle *fullname* within :attr:`path`. | ||
| 944 | - | ||
| 945 | - .. deprecated:: 3.10 | ||
| 946 | - Use :meth:`find_spec` instead. | ||
| 947 | - | ||
| 948 | 840 | .. method:: invalidate_caches() | |
| 949 | 841 | ||
| 950 | 842 | Clear out the internal cache. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,33 +48,6 @@ support. | |||
| 48 | 48 | this function to raise an exception (in line with :func:`os.path.isdir` | |
| 49 | 49 | behavior). | |
| 50 | 50 | ||
| 51 | - | ||
| 52 | - .. class:: ImpImporter(dirname=None) | ||
| 53 | - | ||
| 54 | - :pep:`302` Finder that wraps Python's "classic" import algorithm. | ||
| 55 | - | ||
| 56 | - If *dirname* is a string, a :pep:`302` finder is created that searches that | ||
| 57 | - directory. If *dirname* is ``None``, a :pep:`302` finder is created that | ||
| 58 | - searches the current :data:`sys.path`, plus any modules that are frozen or | ||
| 59 | - built-in. | ||
| 60 | - | ||
| 61 | - Note that :class:`ImpImporter` does not currently support being used by | ||
| 62 | - placement on :data:`sys.meta_path`. | ||
| 63 | - | ||
| 64 | - .. deprecated:: 3.3 | ||
| 65 | - This emulation is no longer needed, as the standard import mechanism | ||
| 66 | - is now fully :pep:`302` compliant and available in :mod:`importlib`. | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - .. class:: ImpLoader(fullname, file, filename, etc) | ||
| 70 | - | ||
| 71 | - :term:`Loader <loader>` that wraps Python's "classic" import algorithm. | ||
| 72 | - | ||
| 73 | - .. deprecated:: 3.3 | ||
| 74 | - This emulation is no longer needed, as the standard import mechanism | ||
| 75 | - is now fully :pep:`302` compliant and available in :mod:`importlib`. | ||
| 76 | - | ||
| 77 | - | ||
| 78 | 51 | .. function:: find_loader(fullname) | |
| 79 | 52 | ||
| 80 | 53 | Retrieve a module :term:`loader` for the given *fullname*. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1177,7 +1177,7 @@ always available. | |||
| 1177 | 1177 | ||
| 1178 | 1178 | :term:`Module specs <module spec>` were introduced in Python 3.4, by | |
| 1179 | 1179 | :pep:`451`. Earlier versions of Python looked for a method called | |
| 1180 | - :meth:`~importlib.abc.MetaPathFinder.find_module`. | ||
| 1180 | + :meth:`!find_module`. | ||
| 1181 | 1181 | This is still called as a fallback if a :data:`meta_path` entry doesn't | |
| 1182 | 1182 | have a :meth:`~importlib.abc.MetaPathFinder.find_spec` method. | |
| 1183 | 1183 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,11 @@ zipimporter Objects | |||
| 74 | 74 | :exc:`ZipImportError` is raised if *archivepath* doesn't point to a valid ZIP | |
| 75 | 75 | archive. | |
| 76 | 76 | ||
| 77 | + .. versionchanged:: 3.12 | ||
| 78 | + | ||
| 79 | + Methods ``find_loader()`` and ``find_module()``, deprecated in 3.10 are | ||
| 80 | + now removed. Use :meth:`find_spec` instead. | ||
| 81 | + | ||
| 77 | 82 | .. method:: create_module(spec) | |
| 78 | 83 | ||
| 79 | 84 | Implementation of :meth:`importlib.abc.Loader.create_module` that returns | |
@@ -89,28 +94,6 @@ zipimporter Objects | |||
| 89 | 94 | .. versionadded:: 3.10 | |
| 90 | 95 | ||
| 91 | 96 | ||
| 92 | - .. method:: find_loader(fullname, path=None) | ||
| 93 | - | ||
| 94 | - An implementation of :meth:`importlib.abc.PathEntryFinder.find_loader`. | ||
| 95 | - | ||
| 96 | - .. deprecated:: 3.10 | ||
| 97 | - | ||
| 98 | - Use :meth:`find_spec` instead. | ||
| 99 | - | ||
| 100 | - | ||
| 101 | - .. method:: find_module(fullname, path=None) | ||
| 102 | - | ||
| 103 | - Search for a module specified by *fullname*. *fullname* must be the fully | ||
| 104 | - qualified (dotted) module name. It returns the zipimporter instance itself | ||
| 105 | - if the module was found, or :const:`None` if it wasn't. The optional | ||
| 106 | - *path* argument is ignored---it's there for compatibility with the | ||
| 107 | - importer protocol. | ||
| 108 | - | ||
| 109 | - .. deprecated:: 3.10 | ||
| 110 | - | ||
| 111 | - Use :meth:`find_spec` instead. | ||
| 112 | - | ||
| 113 | - | ||
| 114 | 97 | .. method:: find_spec(fullname, target=None) | |
| 115 | 98 | ||
| 116 | 99 | An implementation of :meth:`importlib.abc.PathEntryFinder.find_spec`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -324,15 +324,18 @@ modules, and one that knows how to import modules from an :term:`import path` | |||
| 324 | 324 | ||
| 325 | 325 | .. versionchanged:: 3.4 | |
| 326 | 326 | The :meth:`~importlib.abc.MetaPathFinder.find_spec` method of meta path | |
| 327 | - finders replaced :meth:`~importlib.abc.MetaPathFinder.find_module`, which | ||
| 327 | + finders replaced :meth:`!find_module`, which | ||
| 328 | 328 | is now deprecated. While it will continue to work without change, the | |
| 329 | 329 | import machinery will try it only if the finder does not implement | |
| 330 | 330 | ``find_spec()``. | |
| 331 | 331 | ||
| 332 | 332 | .. versionchanged:: 3.10 | |
| 333 | - Use of :meth:`~importlib.abc.MetaPathFinder.find_module` by the import system | ||
| 333 | + Use of :meth:`!find_module` by the import system | ||
| 334 | 334 | now raises :exc:`ImportWarning`. | |
| 335 | 335 | ||
| 336 | + .. versionchanged:: 3.12 | ||
| 337 | + ``find_module()`` has been removed. Use :meth:`find_spec` instead. | ||
| 338 | + | ||
| 336 | 339 | ||
| 337 | 340 | Loading | |
| 338 | 341 | ======= | |
@@ -837,7 +840,7 @@ stores finder objects rather than being limited to :term:`importer` objects). | |||
| 837 | 840 | In this way, the expensive search for a particular :term:`path entry` | |
| 838 | 841 | location's :term:`path entry finder` need only be done once. User code is | |
| 839 | 842 | free to remove cache entries from :data:`sys.path_importer_cache` forcing | |
| 840 | - the path based finder to perform the path entry search again [#fnpic]_. | ||
| 843 | + the path based finder to perform the path entry search again. | ||
| 841 | 844 | ||
| 842 | 845 | If the path entry is not present in the cache, the path based finder iterates | |
| 843 | 846 | over every callable in :data:`sys.path_hooks`. Each of the :term:`path entry | |
@@ -887,21 +890,21 @@ module. ``find_spec()`` returns a fully populated spec for the module. | |||
| 887 | 890 | This spec will always have "loader" set (with one exception). | |
| 888 | 891 | ||
| 889 | 892 | To indicate to the import machinery that the spec represents a namespace | |
| 890 | - :term:`portion`, the path entry finder sets "submodule_search_locations" to | ||
| 893 | + :term:`portion`, the path entry finder sets ``submodule_search_locations`` to | ||
| 891 | 894 | a list containing the portion. | |
| 892 | 895 | ||
| 893 | 896 | .. versionchanged:: 3.4 | |
| 894 | 897 | :meth:`~importlib.abc.PathEntryFinder.find_spec` replaced | |
| 895 | - :meth:`~importlib.abc.PathEntryFinder.find_loader` and | ||
| 896 | - :meth:`~importlib.abc.PathEntryFinder.find_module`, both of which | ||
| 898 | + :meth:`!find_loader` and | ||
| 899 | + :meth:`!find_module`, both of which | ||
| 897 | 900 | are now deprecated, but will be used if ``find_spec()`` is not defined. | |
| 898 | 901 | ||
| 899 | 902 | Older path entry finders may implement one of these two deprecated methods | |
| 900 | 903 | instead of ``find_spec()``. The methods are still respected for the | |
| 901 | 904 | sake of backward compatibility. However, if ``find_spec()`` is | |
| 902 | 905 | implemented on the path entry finder, the legacy methods are ignored. | |
| 903 | 906 | ||
| 904 | - :meth:`~importlib.abc.PathEntryFinder.find_loader` takes one argument, the | ||
| 907 | + :meth:`!find_loader` takes one argument, the | ||
| 905 | 908 | fully qualified name of the module being imported. ``find_loader()`` | |
| 906 | 909 | returns a 2-tuple where the first item is the loader and the second item | |
| 907 | 910 | is a namespace :term:`portion`. | |
@@ -920,10 +923,13 @@ a list containing the portion. | |||
| 920 | 923 | ``find_loader()`` in preference to ``find_module()``. | |
| 921 | 924 | ||
| 922 | 925 | .. versionchanged:: 3.10 | |
| 923 | - Calls to :meth:`~importlib.abc.PathEntryFinder.find_module` and | ||
| 924 | - :meth:`~importlib.abc.PathEntryFinder.find_loader` by the import | ||
| 926 | + Calls to :meth:`!find_module` and | ||
| 927 | + :meth:`!find_loader` by the import | ||
| 925 | 928 | system will raise :exc:`ImportWarning`. | |
| 926 | 929 | ||
| 930 | + .. versionchanged:: 3.12 | ||
| 931 | + ``find_module()`` and ``find_loader()`` have been removed. | ||
| 932 | + | ||
| 927 | 933 | ||
| 928 | 934 | Replacing the standard import system | |
| 929 | 935 | ==================================== | |
@@ -1045,8 +1051,8 @@ The original specification for :data:`sys.meta_path` was :pep:`302`, with | |||
| 1045 | 1051 | subsequent extension in :pep:`420`. | |
| 1046 | 1052 | ||
| 1047 | 1053 | :pep:`420` introduced :term:`namespace packages <namespace package>` for | |
| 1048 | - Python 3.3. :pep:`420` also introduced the :meth:`find_loader` protocol as an | ||
| 1049 | - alternative to :meth:`find_module`. | ||
| 1054 | + Python 3.3. :pep:`420` also introduced the :meth:`!find_loader` protocol as an | ||
| 1055 | + alternative to :meth:`!find_module`. | ||
| 1050 | 1056 | ||
| 1051 | 1057 | :pep:`366` describes the addition of the ``__package__`` attribute for | |
| 1052 | 1058 | explicit relative imports in main modules. | |
@@ -1073,9 +1079,3 @@ methods to finders and loaders. | |||
| 1073 | 1079 | module may replace itself in :data:`sys.modules`. This is | |
| 1074 | 1080 | implementation-specific behavior that is not guaranteed to work in other | |
| 1075 | 1081 | Python implementations. | |
| 1076 | - | ||
| 1077 | - .. [#fnpic] In legacy code, it is possible to find instances of | ||
| 1078 | - :class:`imp.NullImporter` in the :data:`sys.path_importer_cache`. It | ||
| 1079 | - is recommended that code be changed to use ``None`` instead. See | ||
| 1080 | - :ref:`portingpythoncode` for more details. Note that the ``imp`` module | ||
| 1081 | - was removed in Python 3.12. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -728,7 +728,7 @@ module: | |||
| 728 | 728 | ||
| 729 | 729 | Importer objects must have a single method, ``find_module(fullname, | |
| 730 | 730 | path=None)``. *fullname* will be a module or package name, e.g. ``string`` or | |
| 731 | - ``distutils.core``. :meth:`find_module` must return a loader object that has a | ||
| 731 | + ``distutils.core``. :meth:`!find_module` must return a loader object that has a | ||
| 732 | 732 | single method, ``load_module(fullname)``, that creates and returns the | |
| 733 | 733 | corresponding module object. | |
| 734 | 734 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments