Skip to content

Commit 1f690c0

Browse files
committed
fix annotating __init__.py files by stripping __init__ from modpath
1 parent d003335 commit 1f690c0

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def test_to_mod_src_layout():
3434
assert _to_mod('src/foo.py', ('.', 'src')) == 'foo'
3535
assert _to_mod('bar.py', ('.', 'src')) == 'bar'
3636

37+
def test_to_mod_init_files():
38+
assert _to_mod('a/__init__.py', ('.',)) == 'a'
39+
assert _to_mod('a/__init__b.py', ('.',)) == 'a.__init__b'
40+
assert _to_mod('a/__init__b/c.py', ('.',)) == 'a.__init__b.c'
41+
3742

3843
def _find_untyped(s):
3944
visitor = FindUntyped()

0 commit comments

Comments
 (0)