Content-Length: 283227 | pFad | https://github.com/python/cpython/issues/125614

ad [3.14] annotationlib - `get_annotations` with `Format.FORWARDREF` returns `_Stringifier` instances instead of ForwardRef for `module.type` annotations where the module is not loaded · Issue #125614 · python/cpython · GitHub
Skip to content

[3.14] annotationlib - get_annotations with Format.FORWARDREF returns _Stringifier instances instead of ForwardRef for module.type annotations where the module is not loaded #125614

Description

@DavidCEllis

Bug report

Bug description:

Tested on 3.14.0a1 - related to implementation of PEP 649 / PEP 749 - #119180

If a type uses dotted access but can't be evaluated, get_annotations returns _Stringifier objects instead of ForwardRef objects.

from annotationlib import get_annotations, Format

class Example:
    dotted: typing.Any
    undotted: Any

ann = get_annotations(Example, format=Format.FORWARDREF)

for name, value in ann.items():
    print(f"{name!r}: {value!r} | type: {type(value)!r}")

Output:

'dotted': typing.Any | type: <class 'annotationlib._Stringifier'>
'undotted': ForwardRef('Any') | type: <class 'annotationlib.ForwardRef'>

I'd expect to see ForwardRef('typing.Any') here so this was surprising. I also found another bug related to dotted access but not related to Stringifiers that I'll raise separately.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/python/cpython/issues/125614

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy