Skip to content

Commit

Permalink
- fixed missing __init__.py in test;
Browse files Browse the repository at this point in the history
- added always including full __new__ method, if present, as it
  seems important for the LLM to know;
  • Loading branch information
jaltmayerpizzorno committed Aug 21, 2024
1 parent 5b02b9b commit 58928ed
Show file tree
Hide file tree
Showing 2 changed files with 20 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 @@ -105,7 +105,8 @@ def _summarize(path: T.List[ast.AST]) -> ast.AST:
path[-1] = copy.deepcopy(path[-1])
for c in ast.iter_child_nodes(path[-1]):
if (isinstance(c, ast.ClassDef) or
(isinstance(c, (ast.FunctionDef, ast.AsyncFunctionDef)) and c.name != "__init__")):
(isinstance(c, (ast.FunctionDef, ast.AsyncFunctionDef)) and \
c.name not in ("__init__", "__new__"))):
# Leave "__init__" unmodified as it's likely to contain important member information
c.body = [ast.Expr(ast.Constant(value=ast.literal_eval("...")))]

Expand Down
18 changes: 18 additions & 0 deletions tests/test_codeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ def bar(self):
def func(x: C):
x.foo()
class D:
def __new__(cls, *args, **kwargs):
return super().__new__(cls)
def d(self):
pass
"""
)

Expand All @@ -197,6 +204,16 @@ def bar(self):
..."""
)

assert codeinfo.get_info(tree, 'D') == textwrap.dedent('''\
class D:
def __new__(cls, *args, **kwargs):
return super().__new__(cls)
def d(self):
...'''
)

assert codeinfo.get_info(tree, 'C.foo') == textwrap.dedent("""\
class C:
...
Expand Down Expand Up @@ -331,6 +348,7 @@ def test_get_info_name_includes_module_fqn(import_fixture):
tmp_path = import_fixture

(tmp_path / "foo").mkdir()
(tmp_path / "foo" / "__init__.py").write_text("")
(tmp_path / "foo" / "bar.py").write_text(textwrap.dedent("""\
class C:
pass
Expand Down

0 comments on commit 58928ed

Please sign in to comment.