Skip to content

Commit

Permalink
- fixed handling searches for a module that can't be found;
Browse files Browse the repository at this point in the history
  • Loading branch information
jaltmayerpizzorno committed Aug 28, 2024
1 parent 8b548f2 commit c06f3a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/coverup/codeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_codeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c06f3a1

Please sign in to comment.