Skip to content

annotationlib - evaluating forward references in STRING format can 'leak' internal names #148680

Description

@DavidCEllis

Bug report

Bug description:

If a ForwardRef object needs internal names to store values of known objects these internal names currently replace the type_repr of the objects they represent when the ForwardRef is evaluated as Format.STRING or when looking at the repr.

If it was just the repr I'd probably put this as a feature request but as it makes the STRING format arguably 'wrong' I think it should be considered a bug.

fromannotationlibimportget_annotations, FormatclassExample:
a: ref|strann=get_annotations(Example, format=Format.FORWARDREF)['a']
print(ann)
print(ann.evaluate(format=Format.STRING))

On 3.14 or Main:

ForwardRef('ref | __annotationlib_name_1__', is_class=True, owner=<class'__main__.Example'>)
ref|__annotationlib_name_1__

Expected:

ForwardRef('ref | str', is_class=True, owner=<class'__main__.Example'>)
ref|str

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions