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

Skip to content

Commit 0ffe6a9

Browse files
committed
Fix a minor inconsistency in capitalization for the 'No module named' exception
message in importlib. Thanks to Éric Araujo for spotting the inconsistency.
1 parent 8fb9b86 commit 0ffe6a9

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
758758

759759
_IMPLICIT_META_PATH = [BuiltinImporter, FrozenImporter, _DefaultPathFinder]
760760

761+
_ERR_MSG = 'No module named {}'
762+
761763
def _gcd_import(name, package=None, level=0):
762764
"""Import and return the module based on its name, the package the call is
763765
being made from, and the level adjustment.
@@ -808,16 +810,16 @@ def _gcd_import(name, package=None, level=0):
808810
try:
809811
path = parent_module.__path__
810812
except AttributeError:
811-
raise ImportError("no module named {}; "
812-
"{} is not a package".format(name, parent))
813+
msg = (_ERR_MSG + '; {} is not a package').format(name, parent)
814+
raise ImportError(msg)
813815
meta_path = sys.meta_path + _IMPLICIT_META_PATH
814816
for finder in meta_path:
815817
loader = finder.find_module(name, path)
816818
if loader is not None:
817819
loader.load_module(name)
818820
break
819821
else:
820-
raise ImportError("No module named {0}".format(name))
822+
raise ImportError(_ERR_MSG.format(name))
821823
# Backwards-compatibility; be nicer to skip the dict lookup.
822824
module = sys.modules[name]
823825
if parent:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Core and Builtins
1818
Library
1919
-------
2020

21+
- Make the 'No module named' exception message from importlib consistent.
22+
2123
- Issue #10443: Add the SSLContext.set_default_verify_paths() method.
2224

2325
- Issue #10440: Support RUSAGE_THREAD as a constant in the resource module.

0 commit comments

Comments
 (0)