mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-36298: Raise ModuleNotFoundError in pyclbr when a module can't be found (GH-12358)
Before, an `AttributeError` was raised due to trying to access an attribute that exists on specs but having received `None` instead for a non-existent module. https://bugs.python.org/issue36298
This commit is contained in:
parent
dd7c4ceed9
commit
5086589305
3 changed files with 29 additions and 4 deletions
|
@ -160,17 +160,20 @@ def _readmodule(module, path, inpackage=None):
|
|||
else:
|
||||
search_path = path + sys.path
|
||||
spec = importlib.util._find_spec_from_path(fullmodule, search_path)
|
||||
if spec is None:
|
||||
raise ModuleNotFoundError(f"no module named {fullmodule!r}", name=fullmodule)
|
||||
_modules[fullmodule] = tree
|
||||
# Is module a package?
|
||||
if spec.submodule_search_locations is not None:
|
||||
tree['__path__'] = spec.submodule_search_locations
|
||||
try:
|
||||
source = spec.loader.get_source(fullmodule)
|
||||
if source is None:
|
||||
return tree
|
||||
except (AttributeError, ImportError):
|
||||
# If module is not Python source, we cannot do anything.
|
||||
return tree
|
||||
else:
|
||||
if source is None:
|
||||
return tree
|
||||
|
||||
fname = spec.loader.get_filename(fullmodule)
|
||||
return _create_tree(fullmodule, path, fname, source, tree, inpackage)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue