Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/annotationlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ def _rewrite_star_unpack(arg):
"""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
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_annotationlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,9 @@ def test_stringized_annotations_with_star_unpack(self):
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
: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.
Loading