Skip to content

Fix stringified bare ClassVar type hints#782

Open
Sanjays2402 wants to merge 1 commit into
python:mainfrom
Sanjays2402:fix/stringified-classvar-hints
Open

Fix stringified bare ClassVar type hints#782
Sanjays2402 wants to merge 1 commit into
python:mainfrom
Sanjays2402:fix/stringified-classvar-hints

Conversation

@Sanjays2402

Copy link
Copy Markdown

On Python 3.9 and 3.10, get_type_hints() treats a stringified bare ClassVar as a forward reference and rejects it with TypeError. This backports the class-aware evaluation behavior for ClassVar and adds coverage for inherited annotations.

Fixes #643.

Python 3.9 and 3.10 reject a bare ClassVar while evaluating a
ForwardRef, so get_type_hints() raises for postponed annotations.
Evaluate class annotations through the newer class-aware path and allow
the bare ClassVar special form, with coverage for inherited hints.

Fixes python#643
@python-cla-bot

python-cla-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.27%. Comparing base (83400e9) to head (cf85a28).

@@           Coverage Diff           @@
##             main     #782   +/-   ##
=======================================
  Coverage   97.26%   97.27%           
=======================================
  Files           3        3           
  Lines        7860     7885   +25     
=======================================
+ Hits         7645     7670   +25     
  Misses        215      215           
Flag Coverage Δ
3.10 88.89% <100.00%> (+0.03%) ⬆️
3.10.4 88.89% <100.00%> (+0.03%) ⬆️
3.11 87.83% <30.76%> (-0.20%) ⬇️
3.11.0 87.08% <30.76%> (-0.19%) ⬇️
3.12 87.77% <30.76%> (-0.20%) ⬇️
3.12.0 87.76% <30.76%> (-0.20%) ⬇️
3.13 83.20% <23.07%> (-0.19%) ⬇️
3.13.0 83.90% <23.07%> (-0.20%) ⬇️
3.14 79.35% <23.07%> (-0.19%) ⬇️
3.9 89.55% <96.15%> (+0.02%) ⬆️
3.9.12 89.55% <96.15%> (+0.02%) ⬆️
pypy3.10 88.72% <100.00%> (+0.03%) ⬆️
pypy3.11 87.69% <30.76%> (-0.19%) ⬇️
pypy3.9 89.39% <96.15%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/test_typing_extensions.py 98.23% <100.00%> (+<0.01%) ⬆️
src/typing_extensions.py 94.06% <100.00%> (+0.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backport support for get_type_hints on lone stringified ClassVar

1 participant