From c06f3a16a72e988652ae838aeb8519f06cc19a11 Mon Sep 17 00:00:00 2001 From: Juan Altmayer Pizzorno Date: Wed, 28 Aug 2024 13:47:56 -0400 Subject: [PATCH] - fixed handling searches for a module that can't be found; --- src/coverup/codeinfo.py | 3 ++- tests/test_codeinfo.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/coverup/codeinfo.py b/src/coverup/codeinfo.py index aabea3c..7683206 100644 --- a/src/coverup/codeinfo.py +++ b/src/coverup/codeinfo.py @@ -123,9 +123,10 @@ def _find_name_path(module: ast.Module, name: T.List[str], *, paths_seen: T.Set[ """Looks for a symbol's definition by its name, returning the "path" of ast.ClassDef, ast.Import, etc., crossed to find it. """ + if not module: return None + _debug(f"looking up {name} in {module.path}") - if not module: return None if not paths_seen: paths_seen = set() if module.path in paths_seen: return None paths_seen.add(module.path) diff --git a/tests/test_codeinfo.py b/tests/test_codeinfo.py index 1b88e93..52db77a 100644 --- a/tests/test_codeinfo.py +++ b/tests/test_codeinfo.py @@ -248,6 +248,22 @@ def a(self): ) +def test_get_info_method_from_parent_parent_missing(import_fixture): + tmp_path = import_fixture + + code = tmp_path / "foo.py" + code.write_text(textwrap.dedent("""\ + from doesnotexist import A + + class B(A): + pass + """ + )) + + tree = codeinfo.parse_file(code) + assert codeinfo.get_info(tree, 'B.a') == None + + def test_get_info_method_from_parent_imported(import_fixture): tmp_path = import_fixture