Skip to content

get_type_hints crashes for local types with __future__ annotations #73

@francois-rozet

Description

@francois-rozet

The following code crashes, but only if importing annotations. Tested with Python 3.12, 3.13 and 3.14.

from __future__ import annotations

from typing import get_type_hints


def f():
    class X:
        pass

    class Y:
        x: X

    print(get_type_hints(Y))


f()  # NameError: name 'X' is not defined
from typing import get_type_hints


def f():
    class X:
        pass

    class Y:
        x: X

    print(get_type_hints(Y))


f()  # prints {'x': <class '__main__.f.<locals>.X'>}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions