diff options
author | Brett Cannon <brettcannon@users.noreply.github.com> | 2019-03-22 22:16:50 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-03-22 22:16:50 (GMT) |
commit | 5086589305ff5538709856b27314b68f06ae93db (patch) | |
tree | 53f1842d1dc8c9ae109dca4ccfc43941b5de320d /Lib/pyclbr.py | |
parent | dd7c4ceed90792f711347024852d4cf883a9ab9e (diff) | |
download | cpython-5086589305ff5538709856b27314b68f06ae93db.zip cpython-5086589305ff5538709856b27314b68f06ae93db.tar.gz cpython-5086589305ff5538709856b27314b68f06ae93db.tar.bz2 |
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
Diffstat (limited to 'Lib/pyclbr.py')
-rw-r--r-- | Lib/pyclbr.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py index 2c798df..8fd0523 100644 --- a/Lib/pyclbr.py +++ b/Lib/pyclbr.py @@ -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) |