Skip to content

Commit

Permalink
Crashes on empty elems (#58)
Browse files Browse the repository at this point in the history
closes #57
  • Loading branch information
MarcoGorelli authored Feb 14, 2023
1 parent 41b7bdf commit d52670a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions autotyping/guess_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def guess_type_from_argname(name: str) -> Tuple[Optional[str], List[str]]:
# (container)_of_<name>(s)
# e.g. set_of_widths => Set[int]
m = re.fullmatch(
rf"(?P<elems>\w*?)_?(?P<container>{containers})", name
) or re.fullmatch(rf"(?P<container>{containers})_of_(?P<elems>\w*)", name)
rf"(?P<elems>\w+?)_?(?P<container>{containers})", name
) or re.fullmatch(rf"(?P<container>{containers})_of_(?P<elems>\w+)", name)
if m:
# only do a simple container match
# and don't check all of BOOL_NAMES to not trigger on stuff like "save_list"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_codemod.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,17 @@ def __exit__(self, a, b, c, d):
"""
self.assertCodemod(before, after, annotate_magics=True)

def test_empty_elems(self) -> None:
before = """
def foo(iterables):
...
"""
after = """
def foo(iterables) -> None:
...
"""
self.assertCodemod(before, after, none_return=True, guess_common_names=True)

def test_annotate_imprecise_magics(self) -> None:
before = """
def __iter__():
Expand Down

0 comments on commit d52670a

Please sign in to comment.