Skip to content

Backport support for get_type_hints on lone stringified ClassVar #643

@ItsDrike

Description

@ItsDrike

Currently, both typing.get_type_hints and typing_extensions.get_type_hints fail on a lone stringified ClassVar annotation in Python 3.9 and 3.10:

from __future__ import annotations

from typing import ClassVar, get_type_hints as get_type_hints
from typing_extensions import get_type_hints as get_type_hints_ext


class Foo:
    MY_CLASS_CONSTANT: ClassVar = 5


try:
    _ = get_type_hints(Foo)
except TypeError as exc:
    print(exc)

try:
    _ = get_type_hints_ext(Foo)
except TypeError as exc:
    print(exc)

This is unfortunate, as python/cpython#90711 addressed this for Python 3.11+, so it would be nice if typing-extensions backported this fix for older python versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions