Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f410ce8

Browse files
committed
Issue #15502: Refactor some code.
1 parent e9175bd commit f410ce8

3 files changed

Lines changed: 4174 additions & 4171 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,21 @@ def _requires_frozen_wrapper(self, fullname):
607607
return _requires_frozen_wrapper
608608

609609

610+
def _find_module_shim(self, fullname):
611+
"""Try to find a loader for the specified module by delegating to
612+
self.find_loader()."""
613+
# Call find_loader(). If it returns a string (indicating this
614+
# is a namespace package portion), generate a warning and
615+
# return None.
616+
loader, portions = self.find_loader(fullname)
617+
if loader is None and len(portions):
618+
msg = "Not importing directory {}: missing __init__"
619+
_warnings.warn(msg.format(portions[0]), ImportWarning)
620+
return loader
621+
622+
623+
624+
610625
# Loaders #####################################################################
611626

612627
class BuiltinImporter:
@@ -1305,17 +1320,7 @@ def invalidate_caches(self):
13051320
"""Invalidate the directory mtime."""
13061321
self._path_mtime = -1
13071322

1308-
def find_module(self, fullname):
1309-
"""Try to find a loader for the specified module."""
1310-
# Call find_loader(). If it returns a string (indicating this
1311-
# is a namespace package portion), generate a warning and
1312-
# return None.
1313-
loader, portions = self.find_loader(fullname)
1314-
assert len(portions) in [0, 1]
1315-
if loader is None and len(portions):
1316-
msg = "Not importing directory {}: missing __init__"
1317-
_warnings.warn(msg.format(portions[0]), ImportWarning)
1318-
return loader
1323+
find_module = _find_module_shim
13191324

13201325
def find_loader(self, fullname):
13211326
"""Try to find a loader for the specified module, or the namespace

Lib/importlib/abc.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ def find_loader(self, fullname):
7878
"""
7979
raise NotImplementedError
8080

81-
def find_module(self, fullname):
82-
"""Compatibility function which is the equivalent of
83-
self.find_loader(fullname)[0]."""
84-
return self.find_loader(fullname)[0]
81+
find_module = _bootstrap._find_module_shim
8582

8683
def invalidate_caches(self):
8784
"""An optional method for clearing the finder's cache, if any.

0 commit comments

Comments
 (0)