15r10nk · GitHub

Bug report

Bug description:

I found the following bug while fuzzing with pysource-codegen

from annotationlib import get_annotations, Format
def name_3() -> t'{ {}}':
    pass
get_annotations(name_3, format=Format.STRING)

output (Python 3.14.0rc2+):

Traceback (most recent call last):
  File "/home/frank/projects/pysource-playground/crash.py", line 5, in <module>
    get_annotations(name_3, format=Format.STRING)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frank/projects/cpython/install/lib/python3.14/annotationlib.py", line 914, in get_annotations
    ann = _get_and_call_annotate(obj, format)
  File "/home/frank/projects/cpython/install/lib/python3.14/annotationlib.py", line 1034, in _get_and_call_annotate
    ann = call_annotate_function(annotate, format, owner=obj)
  File "/home/frank/projects/cpython/install/lib/python3.14/annotationlib.py", line 683, in call_annotate_function
    key: _stringify_single(val)
         ~~~~~~~~~~~~~~~~~^^^^^
  File "/home/frank/projects/cpython/install/lib/python3.14/annotationlib.py", line 814, in _stringify_single
    return ast.unparse(_template_to_ast(anno))
                       ~~~~~~~~~~~~~~~~^^^^^^
  File "/home/frank/projects/cpython/install/lib/python3.14/annotationlib.py", line 573, in _template_to_ast
    value=ast.parse(part.expression),
          ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/frank/projects/cpython/install/lib/python3.14/ast.py", line 46, in parse
    return compile(source, filename, mode, flags,
                   _feature_version=feature_version, optimize=optimize)
  File "<unknown>", line 1
    {}
IndentationError: unexpected indent

I think the problem is the space before {} but this space is required to distinguish it from an escaped {.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Read the original on github.com ↗