mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Issue #13959: Introduce importlib.find_loader().
The long-term goal is to deprecate imp.find_module() in favour of this API, but it will take some time as some APIs explicitly return/use what imp.find_module() returns.
This commit is contained in:
parent
acc0c181a8
commit
ee78a2b51c
5 changed files with 105 additions and 10 deletions
|
@ -86,6 +86,20 @@ Functions
|
|||
that was imported (e.g. ``pkg.mod``), while :func:`__import__` returns the
|
||||
top-level package or module (e.g. ``pkg``).
|
||||
|
||||
.. function:: find_loader(name, path=None)
|
||||
|
||||
Find the loader for a module, optionally within the specified *path*. If the
|
||||
module is in :attr:`sys.modules`, then ``sys.modules[name].__loader__`` is
|
||||
returned (unless the loader would be ``None``, in which case
|
||||
:exc:`ValueError` is raised). Otherwise a search using :attr:`sys.meta_path`
|
||||
is done. ``None`` is returned if no loader is found.
|
||||
|
||||
A dotted name does not have its parent's implicitly imported. If that is
|
||||
desired (although not nessarily required to find the loader, it will most
|
||||
likely be needed if the loader actually is used to load the module), then
|
||||
you will have to import the packages containing the module prior to calling
|
||||
this function.
|
||||
|
||||
.. function:: invalidate_caches()
|
||||
|
||||
Invalidate the internal caches of the finders stored at
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue