Skip to content

get_annotations(..., eval_str=True) throws SyntaxError if stringified starred annotation starts with one or more spaces #143517

Closed

Description

@johnslavik

Bug report

Bug description:

import annotationlib

def f(self, *args: ' *tuple[str, int]') -> None: ...

print(annotationlib.get_annotations(f, eval_str=True))

Expected:

{'args': *tuple[str, int], 'return': None}

Got:

Traceback (most recent call last):
  File "/home/bswck/Python/cpython/t.py", line 5, in <module>
    print(annotationlib.get_annotations(f, eval_str=True))
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/bswck/Python/cpython/Lib/annotationlib.py", line 1058, in get_annotations
    else eval(_rewrite_star_unpack(value), globals, locals)
         ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 1
    *tuple[str, int]
    ^
SyntaxError: invalid syntax

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Jan 7, 2026
  2. changed the title [-]`SyntaxError` if stringified starred annotation starts with a space[/-] [+]`get_annotations(..., eval_str=True)` throws `SyntaxError` if stringified starred annotation starts with a space[/+] on Jan 7, 2026
  3. changed the title [-]`get_annotations(..., eval_str=True)` throws `SyntaxError` if stringified starred annotation starts with a space[/-] [+]`get_annotations(..., eval_str=True)` throws `SyntaxError` if stringified starred annotation starts with one or more spaces[/+] on Jan 7, 2026
  4. added a commit that references this issue on Jan 8, 2026
  5. added a commit that references this issue on Jan 8, 2026
  6. added a commit that references this issue on Jan 8, 2026
  7. added a commit that references this issue on Jan 12, 2026
  8. added a commit that references this issue on Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15bugs and security fixestopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions