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.
4 changes: 2 additions & 2 deletions Objects/typevarobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,13 +1451,13 @@ The following syntax creates a parameter specification that defaults\n\
to a callable accepting two positional-only arguments of types int\n\
and str:\n\
\n\
type IntFuncDefault[**P = (int, str)] = Callable[P, int]\n\
type IntFuncDefault[**P = [int, str]] = Callable[P, int]\n\
\n\
For compatibility with Python 3.11 and earlier, ParamSpec objects\n\
can also be created as follows::\n\
\n\
P = ParamSpec('P')\n\
DefaultP = ParamSpec('DefaultP', default=(int, str))\n\
DefaultP = ParamSpec('DefaultP', default=[int, str])\n\
\n\
Parameter specification variables exist primarily for the benefit of\n\
static type checkers. They are used to forward the parameter types of\n\
Expand Down
Loading