Thanks to visit codestin.com
Credit goes to github.com

Skip to content

typing - evaluating forward references in STRING format can 'leak' internal names #150641

Description

@cossor

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

Activity

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

    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