Skip to content

Commit b4c3215

Browse files
committed
Fix crash on invalid type comment
1 parent 5497d7a commit b4c3215

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/com2ann.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def split_function_comment(
411411
is transformed into: ['int', 'str'], 'None'.
412412
"""
413413
typ, _ = split_sub_comment(comment)
414-
if "->" not in typ:
414+
if typ.count("->") != 1:
415415
if not silent:
416416
print("Invalid function type comment:", comment, file=sys.stderr)
417417
return None

src/test_com2ann.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,20 @@ def load_cache(self) -> bool:
374374
""",
375375
)
376376

377+
def test_invalid_return_type(self) -> None:
378+
self.check(
379+
"""
380+
def load_cache(x):
381+
# type: (str) -> bool -> invalid
382+
pass
383+
""",
384+
"""
385+
def load_cache(x):
386+
# type: (str) -> bool -> invalid
387+
pass
388+
""",
389+
)
390+
377391
def test_combined_annotations_single(self) -> None:
378392
self.check(
379393
"""

0 commit comments

Comments
 (0)