Skip to content

Commit 349d321

Browse files
Merge pull request #8 from karimkhaleel/Fix-annotating-__init__.py-files-by-stripping-__init__-from-modpath
fix annotating __init__.py files by stripping __init__ from modpath
2 parents d003335 + 229bc90 commit 349d321

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

auto_type_annotate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def _to_mod(fname: str, roots: tuple[str, ...]) -> str:
3636
relative.removesuffix('.py')
3737
.replace('/', '.')
3838
.replace('\\', '.')
39+
.removesuffix('.__init__')
3940
)
4041
else:
4142
raise AssertionError(f'{fname=} not found in {roots=}')

tests/auto_type_annotate_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def test_to_mod_src_layout():
3535
assert _to_mod('bar.py', ('.', 'src')) == 'bar'
3636

3737

38+
def test_to_mod_init_files():
39+
assert _to_mod('a/__init__.py', ('.',)) == 'a'
40+
assert _to_mod('a/__init__b.py', ('.',)) == 'a.__init__b'
41+
assert _to_mod('a/__init__b/c.py', ('.',)) == 'a.__init__b.c'
42+
43+
3844
def _find_untyped(s):
3945
visitor = FindUntyped()
4046
visitor.visit_module(_MOD, ast.parse(s))

0 commit comments

Comments
 (0)