Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d52670a

Browse files
authored
Crashes on empty elems (#58)
closes #57
1 parent 41b7bdf commit d52670a

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

autotyping/guess_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def guess_type_from_argname(name: str) -> Tuple[Optional[str], List[str]]:
3434
# (container)_of_<name>(s)
3535
# e.g. set_of_widths => Set[int]
3636
m = re.fullmatch(
37-
rf"(?P<elems>\w*?)_?(?P<container>{containers})", name
38-
) or re.fullmatch(rf"(?P<container>{containers})_of_(?P<elems>\w*)", name)
37+
rf"(?P<elems>\w+?)_?(?P<container>{containers})", name
38+
) or re.fullmatch(rf"(?P<container>{containers})_of_(?P<elems>\w+)", name)
3939
if m:
4040
# only do a simple container match
4141
# and don't check all of BOOL_NAMES to not trigger on stuff like "save_list"

tests/test_codemod.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,17 @@ def __exit__(self, a, b, c, d):
330330
"""
331331
self.assertCodemod(before, after, annotate_magics=True)
332332

333+
def test_empty_elems(self) -> None:
334+
before = """
335+
def foo(iterables):
336+
...
337+
"""
338+
after = """
339+
def foo(iterables) -> None:
340+
...
341+
"""
342+
self.assertCodemod(before, after, none_return=True, guess_common_names=True)
343+
333344
def test_annotate_imprecise_magics(self) -> None:
334345
before = """
335346
def __iter__():

0 commit comments

Comments
 (0)