python / python/typing_extensions
Backport support for get_type_hints on lone stringified ClassVar
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 583
- Forks
- 146
- Avg merge
- 10h 11m
- Merged PRs (30d)
- 5
Description
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 https://github.com/python/cpython/issues/90711 addressed this for Python 3.11+, so it would be nice if typing-extensions backported this fix for older python versions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied example on Python 3.9 and 3.10, then inspect the typing_extensions.get_type_hints implementation and its existing tests. Done means both typing.get_type_hints and typing_extensions.get_type_hints handle the lone stringified ClassVar as they do in Python 3.11+.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100