Skip to content

Commit ccddbb1

Browse files
committed
Issue #23936: Clarify what finders are.
Thanks to Raúl Cumplido for the bug report and Thomas Kluyver for the patch.
1 parent f4f25fe commit ccddbb1

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

Doc/glossary.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,14 @@ Glossary
308308
A synonym for :term:`file object`.
309309

310310
finder
311-
An object that tries to find the :term:`loader` for a module. It must
312-
implement either a method named :meth:`find_loader` or a method named
313-
:meth:`find_module`. See :pep:`302` and :pep:`420` for details and
314-
:class:`importlib.abc.Finder` for an :term:`abstract base class`.
311+
An object that tries to find the :term:`loader` for a module that is
312+
being imported.
313+
314+
Since Python 3.3, there are two types of finder: :term:`meta path finders
315+
<meta path finder>` for use with :data:`sys.meta_path`, and :term:`path
316+
entry finders <path entry finder>` for use with :data:`sys.path_hooks`.
317+
318+
See :pep:`302`, :pep:`420` and :pep:`451` for much more detail.
315319

316320
floor division
317321
Mathematical division that rounds down to nearest integer. The floor
@@ -593,10 +597,13 @@ Glossary
593597
:class:`collections.OrderedDict` and :class:`collections.Counter`.
594598

595599
meta path finder
596-
A finder returned by a search of :data:`sys.meta_path`. Meta path
600+
A :term:`finder` returned by a search of :data:`sys.meta_path`. Meta path
597601
finders are related to, but different from :term:`path entry finders
598602
<path entry finder>`.
599603

604+
See :class:`importlib.abc.MetaPathFinder` for the methods that meta path
605+
finders implement.
606+
600607
metaclass
601608
The class of a class. Class definitions create a class name, a class
602609
dictionary, and a list of base classes. The metaclass is responsible for
@@ -630,7 +637,7 @@ Glossary
630637

631638
module spec
632639
A namespace containing the import-related information used to load a
633-
module.
640+
module. An instance of :class:`importlib.machinery.ModuleSpec`.
634641

635642
MRO
636643
See :term:`method resolution order`.
@@ -757,6 +764,9 @@ Glossary
757764
(i.e. a :term:`path entry hook`) which knows how to locate modules given
758765
a :term:`path entry`.
759766

767+
See :class:`importlib.abc.PathEntryFinder` for the methods that path entry
768+
finders implement.
769+
760770
path entry hook
761771
A callable on the :data:`sys.path_hook` list which returns a :term:`path
762772
entry finder` if it knows how to find modules on a specific :term:`path

Doc/library/sys.rst

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -774,19 +774,32 @@ always available.
774774

775775
.. data:: meta_path
776776

777-
A list of :term:`finder` objects that have their :meth:`find_module`
778-
methods called to see if one of the objects can find the module to be
779-
imported. The :meth:`find_module` method is called at least with the
780-
absolute name of the module being imported. If the module to be imported is
781-
contained in package then the parent package's :attr:`__path__` attribute
782-
is passed in as a second argument. The method returns ``None`` if
783-
the module cannot be found, else returns a :term:`loader`.
784-
785-
:data:`sys.meta_path` is searched before any implicit default finders or
786-
:data:`sys.path`.
787-
788-
See :pep:`302` for the original specification.
789-
777+
A list of :term:`meta path finder` objects that have their
778+
:meth:`~importlib.abc.MetaPathFinder.find_spec` methods called to see if one
779+
of the objects can find the module to be imported. The
780+
:meth:`~importlib.abc.MetaPathFinder.find_spec` method is called with at
781+
least the absolute name of the module being imported. If the module to be
782+
imported is contained in a package, then the parent package's :attr:`__path__`
783+
attribute is passed in as a second argument. The method returns a
784+
:term:`module spec`, or ``None`` if the module cannot be found.
785+
786+
.. seealso::
787+
788+
:class:`importlib.abc.MetaPathFinder`
789+
The abstract base class defining the interface of finder objects on
790+
:data:`meta_path`.
791+
:class:`importlib.machinery.ModuleSpec`
792+
The concrete class which
793+
:meth:`~importlib.abc.MetaPathFinder.find_spec` should return
794+
instances of.
795+
796+
.. versionchanged:: 3.4
797+
798+
:term:`Module specs <module spec>` were introduced in Python 3.4, by
799+
:pep:`451`. Earlier versions of Python looked for a method called
800+
:meth:`~importlib.abc.MetaPathFinder.find_module`.
801+
This is still called as a fallback if a :data:`meta_path` entry doesn't
802+
have a :meth:`~importlib.abc.MetaPathFinder.find_spec` method.
790803

791804
.. data:: modules
792805

0 commit comments

Comments
 (0)