X Tutup
Skip to content

Commit fdcdd9e

Browse files
committed
Issue python#26896: Disambiguate uses of "importer" with "finder".
Thanks to Oren Milman for the patch.
1 parent 15552c3 commit fdcdd9e

File tree

9 files changed

+32
-32
lines changed

9 files changed

+32
-32
lines changed

Doc/c-api/import.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ Importing Modules
207207
208208
.. c:function:: PyObject* PyImport_GetImporter(PyObject *path)
209209
210-
Return an importer object for a :data:`sys.path`/:attr:`pkg.__path__` item
210+
Return a finder object for a :data:`sys.path`/:attr:`pkg.__path__` item
211211
*path*, possibly by fetching it from the :data:`sys.path_importer_cache`
212212
dict. If it wasn't yet cached, traverse :data:`sys.path_hooks` until a hook
213213
is found that can handle the path item. Return ``None`` if no hook could;
214-
this tells our caller it should fall back to the built-in import mechanism.
215-
Cache the result in :data:`sys.path_importer_cache`. Return a new reference
216-
to the importer object.
214+
this tells our caller that the :term:`path based finder` could not find a
215+
finder for this path item. Cache the result in :data:`sys.path_importer_cache`.
216+
Return a new reference to the finder object.
217217
218218
219219
.. c:function:: void _PyImport_Init()

Doc/library/pkgutil.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ support.
4646

4747
.. class:: ImpImporter(dirname=None)
4848

49-
:pep:`302` Importer that wraps Python's "classic" import algorithm.
49+
:pep:`302` Finder that wraps Python's "classic" import algorithm.
5050

51-
If *dirname* is a string, a :pep:`302` importer is created that searches that
52-
directory. If *dirname* is ``None``, a :pep:`302` importer is created that
51+
If *dirname* is a string, a :pep:`302` finder is created that searches that
52+
directory. If *dirname* is ``None``, a :pep:`302` finder is created that
5353
searches the current :data:`sys.path`, plus any modules that are frozen or
5454
built-in.
5555

@@ -88,9 +88,9 @@ support.
8888

8989
.. function:: get_importer(path_item)
9090

91-
Retrieve a :pep:`302` importer for the given *path_item*.
91+
Retrieve a :pep:`302` finder for the given *path_item*.
9292

93-
The returned importer is cached in :data:`sys.path_importer_cache` if it was
93+
The returned finder is cached in :data:`sys.path_importer_cache` if it was
9494
newly created by a path hook.
9595

9696
The cache (or part of it) can be cleared manually if a rescan of
@@ -121,16 +121,16 @@ support.
121121

122122
.. function:: iter_importers(fullname='')
123123

124-
Yield :pep:`302` importers for the given module name.
124+
Yield :pep:`302` finders for the given module name.
125125

126-
If fullname contains a '.', the importers will be for the package
126+
If fullname contains a '.', the finders will be for the package
127127
containing fullname, otherwise they will be all registered top level
128-
importers (i.e. those on both sys.meta_path and sys.path_hooks).
128+
finders (i.e. those on both sys.meta_path and sys.path_hooks).
129129

130130
If the named module is in a package, that package is imported as a side
131131
effect of invoking this function.
132132

133-
If no module name is specified, all top level importers are produced.
133+
If no module name is specified, all top level finders are produced.
134134

135135
.. versionchanged:: 3.3
136136
Updated to be based directly on :mod:`importlib` rather than relying

Lib/pkgutil.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def read_code(stream):
4545

4646

4747
def walk_packages(path=None, prefix='', onerror=None):
48-
"""Yields (module_loader, name, ispkg) for all modules recursively
48+
"""Yields (module_finder, name, ispkg) for all modules recursively
4949
on path, or, if path is None, all accessible modules.
5050
5151
'path' should be either None or a list of paths to look for
@@ -102,7 +102,7 @@ def seen(p, m={}):
102102

103103

104104
def iter_modules(path=None, prefix=''):
105-
"""Yields (module_loader, name, ispkg) for all submodules on path,
105+
"""Yields (module_finder, name, ispkg) for all submodules on path,
106106
or, if path is None, all top-level modules on sys.path.
107107
108108
'path' should be either None or a list of paths to look for
@@ -184,10 +184,10 @@ def _import_imp():
184184
imp = importlib.import_module('imp')
185185

186186
class ImpImporter:
187-
"""PEP 302 Importer that wraps Python's "classic" import algorithm
187+
"""PEP 302 Finder that wraps Python's "classic" import algorithm
188188
189-
ImpImporter(dirname) produces a PEP 302 importer that searches that
190-
directory. ImpImporter(None) produces a PEP 302 importer that searches
189+
ImpImporter(dirname) produces a PEP 302 finder that searches that
190+
directory. ImpImporter(None) produces a PEP 302 finder that searches
191191
the current sys.path, plus any modules that are frozen or built-in.
192192
193193
Note that ImpImporter does not currently support being used by placement
@@ -395,9 +395,9 @@ def iter_zipimport_modules(importer, prefix=''):
395395

396396

397397
def get_importer(path_item):
398-
"""Retrieve a PEP 302 importer for the given path item
398+
"""Retrieve a PEP 302 finder for the given path item
399399
400-
The returned importer is cached in sys.path_importer_cache
400+
The returned finder is cached in sys.path_importer_cache
401401
if it was newly created by a path hook.
402402
403403
The cache (or part of it) can be cleared manually if a
@@ -419,16 +419,16 @@ def get_importer(path_item):
419419

420420

421421
def iter_importers(fullname=""):
422-
"""Yield PEP 302 importers for the given module name
422+
"""Yield PEP 302 finders for the given module name
423423
424-
If fullname contains a '.', the importers will be for the package
424+
If fullname contains a '.', the finders will be for the package
425425
containing fullname, otherwise they will be all registered top level
426-
importers (i.e. those on both sys.meta_path and sys.path_hooks).
426+
finders (i.e. those on both sys.meta_path and sys.path_hooks).
427427
428428
If the named module is in a package, that package is imported as a side
429429
effect of invoking this function.
430430
431-
If no module name is specified, all top level importers are produced.
431+
If no module name is specified, all top level finders are produced.
432432
"""
433433
if fullname.startswith('.'):
434434
msg = "Relative module name {!r} not supported".format(fullname)

Lib/runpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _run_module_code(code, init_globals=None,
9898
# may be cleared when the temporary module goes away
9999
return mod_globals.copy()
100100

101-
# Helper to get the loader, code and filename for a module
101+
# Helper to get the full name, spec and code for a module
102102
def _get_module_details(mod_name, error=ImportError):
103103
if mod_name.startswith("."):
104104
raise error("Relative module names not supported")
@@ -253,7 +253,7 @@ def run_path(path_name, init_globals=None, run_name=None):
253253
return _run_module_code(code, init_globals, run_name,
254254
pkg_name=pkg_name, script_name=fname)
255255
else:
256-
# Importer is defined for path, so add it to
256+
# Finder is defined for path, so add it to
257257
# the start of sys.path
258258
sys.path.insert(0, path_name)
259259
try:

Lib/test/test_importlib/import_/test_meta_path.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def test_no_path(self):
7676
self.__import__(mod_name)
7777
assert len(log) == 1
7878
args = log[0][0]
79-
kwargs = log[0][1]
8079
# Assuming all arguments are positional.
8180
self.assertEqual(args[0], mod_name)
8281
self.assertIsNone(args[1])

Lib/test/test_importlib/util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ def find_spec(self, fullname, path=None, parent=None):
266266
module = self.modules[fullname]
267267
except KeyError:
268268
return None
269-
is_package = hasattr(module, '__path__')
270269
spec = util.spec_from_file_location(
271270
fullname, module.__file__, loader=self,
272271
submodule_search_locations=getattr(module, '__path__', None))

Lib/test/test_pkgutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def tearDown(self):
205205
del sys.meta_path[0]
206206

207207
def test_getdata_pep302(self):
208-
# Use a dummy importer/loader
208+
# Use a dummy finder/loader
209209
self.assertEqual(pkgutil.get_data('foo', 'dummy'), "Hello, world!")
210210
del sys.modules['foo']
211211

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ Damien Miller
998998
Jason V. Miller
999999
Jay T. Miller
10001000
Katie Miller
1001+
Oren Milman
10011002
Roman Milner
10021003
Julien Miotte
10031004
Andrii V. Mishkovskyi

Python/import.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,12 +950,13 @@ is_builtin(PyObject *name)
950950
}
951951

952952

953-
/* Return an importer object for a sys.path/pkg.__path__ item 'p',
953+
/* Return a finder object for a sys.path/pkg.__path__ item 'p',
954954
possibly by fetching it from the path_importer_cache dict. If it
955955
wasn't yet cached, traverse path_hooks until a hook is found
956956
that can handle the path item. Return None if no hook could;
957-
this tells our caller it should fall back to the builtin
958-
import mechanism. Cache the result in path_importer_cache.
957+
this tells our caller that the path based finder could not find
958+
a finder for this path item. Cache the result in
959+
path_importer_cache.
959960
Returns a borrowed reference. */
960961

961962
static PyObject *

0 commit comments

Comments
 (0)
X Tutup