"""If the given argument annotation expression is a star unpack e.g. `'*Ts'`
rewrite it to a valid expression.
"""
- if arg.startswith("*"):
+ if arg.lstrip().startswith("*"):
return f"({arg},)[0]" # E.g. (*Ts,)[0] or (*tuple[int, int],)[0]
else:
return arg
def f(*args: "*tuple[int, ...]"): ...
self.assertEqual(get_annotations(f, eval_str=True),
{'args': (*tuple[int, ...],)[0]})
+ def f(*args: " *tuple[int, ...]"): ...
+ self.assertEqual(get_annotations(f, eval_str=True),
+ {'args': (*tuple[int, ...],)[0]})
def test_stringized_annotations_on_wrapper(self):
--- /dev/null
+:func:`annotationlib.get_annotations` no longer raises a :exc:`SyntaxError`
+when evaluating a stringified starred annotation that starts with one
+or more whitespace characters followed by a ``*``.
+Patch by Bartosz Sławecki.