Repository: ilevkivskyi/com2ann

Issue:
Invalid type comment causes crash
I used `doc484` to convert doc strings to type annotation comments, and got something like this:
```python
def f() -> float:
    # type: () -> A floating number S such that S*degrees -> meters
    return 1.0
```
When running `com2ann`, that crashed:
```
$ uvx --python 3.10 com2ann -v 10 com2ann-repro.py
File: com2ann-repro.py
INTERNAL ERROR while processing com2ann-repro.py
Please report bug at https://github.com/ilevkivskyi/com2ann/issues
Traceback (most recent call last):
  <CUT>
.../com2ann.py", line 379, in split_function_comment
    arg_list, ret = typ.split('->')
ValueError: too many values to unpack (expected 2)
```
The type comment is obviously faulty, so printing an error instead of crashing would have been nice.

Discussion:

Solution patch:
diff --git a/src/com2ann.py b/src/com2ann.py
index 7a22214..a98cf22 100644
--- a/src/com2ann.py
+++ b/src/com2ann.py
@@ -411,7 +411,7 @@ def split_function_comment(
     is transformed into: ['int', 'str'], 'None'.
     """
     typ, _ = split_sub_comment(comment)
-    if "->" not in typ:
+    if typ.count("->") != 1:
         if not silent:
             print("Invalid function type comment:", comment, file=sys.stderr)
         return None


Test patch:
diff --git a/src/test_com2ann.py b/src/test_com2ann.py
index 973280f..9735778 100644
--- a/src/test_com2ann.py
+++ b/src/test_com2ann.py
@@ -374,6 +374,20 @@ class FunctionTestCase(BaseTestCase):
             """,
         )
 
+    def test_invalid_return_type(self) -> None:
+        self.check(
+            """
+            def load_cache(x):
+                # type: (str) -> bool -> invalid
+                pass
+            """,
+            """
+            def load_cache(x):
+                # type: (str) -> bool -> invalid
+                pass
+            """,
+        )
+
     def test_combined_annotations_single(self) -> None:
         self.check(
             """