cossor · GitHub

Bug report

Bug description:

Resolution of gh-148680 addressed the underlying annotationlib issue without changing the behavior of evaluate_forward_ref.

On 3.14.5:

from annotationlib import Format, get_annotations
from typing import TYPE_CHECKING, evaluate_forward_ref
def test(arg: Iterable[int]) -> None:
    pass
forward_ref = get_annotations(test, format=Format.FORWARDREF)['arg']
assert forward_ref.evaluate(format=Format.STRING) == 'Iterable[int]'
bad_string = evaluate_forward_ref(forward_ref, format=Format.STRING)
assert bad_string == 'Iterable[__annotationlib_name_1__]'
assert bad_string is forward_ref.__forward_arg__
if TYPE_CHECKING:
    from collections.abc import Iterable

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Read the original on github.com ↗