Skip to content

[ty] Revert protocol ClassVar declaration requirement - #27726

Draft
AlexWaygood wants to merge 1 commit into
mainfrom
alex/revert-protocol-classvar-members
Draft

[ty] Revert protocol ClassVar declaration requirement#27726
AlexWaygood wants to merge 1 commit into
mainfrom
alex/revert-protocol-classvar-members

Conversation

@AlexWaygood

@AlexWaygood AlexWaygood commented Aug 13, 2026

Copy link
Copy Markdown
Member

Reverts #27530.

Restore the previous protocol-matching behavior so any type T can satisfy a protocol with a ClassVar member x if T is readable on instances of T, and both readable and writable on type[T].

Cf. python/typing#2340

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Aug 13, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

Typing conformance results regressed ❌

The percentage of diagnostics emitted that were expected errors decreased from 97.14% to 97.14%. The percentage of expected errors that received a diagnostic decreased from 93.44% to 93.43%. The number of fully passing files held steady at 107/137.

Summary

How are test cases classified?

Each test case represents one expected error annotation or a group of annotations sharing a tag. Counts are per test case, not per diagnostic — multiple diagnostics on the same line count as one. Required annotations (E) are true positives when ty flags the expected location and false negatives when it does not. Optional annotations (E?) are true positives when flagged but true negatives (not false negatives) when not. Tagged annotations (E[tag]) require ty to flag exactly one of the tagged lines; tagged multi-annotations (E[tag+]) allow any number up to the tag count. Flagging unexpected locations counts as a false positive.

Metric Old New Diff Outcome
True Positives 1054 1052 -2 ⏬ (❌)
False Positives 31 31 +0
False Negatives 74 74 +0
Total Diagnostics 1127 1125 -2
Precision 97.14% 97.14% -0.01% ⏬ (❌)
Recall 93.44% 93.43% -0.01% ⏬ (❌)
Passing Files 107/137 107/137 +0

Test file breakdown

2 files altered
File True Positives False Positives False Negatives Status
protocols_class_objects.py 4 (-1) ❌ 0 3 ➡️ Neutral
protocols_definition.py 22 (-1) ❌ 0 0 ✅ Still Passing
Total (all files) 1052 (-2) ❌ 31 74 107/137

Optional Diagnostics Removed (2)

2 diagnostics
Test case Diff

protocols_class_objects.py:108

-error[invalid-assignment] Object of type `<class 'ConcreteC3'>` is not assignable to `ProtoC1`

protocols_definition.py:117

-error[invalid-assignment] Object of type `Concrete2_Bad4` is not assignable to `Template2`

@AlexWaygood

Copy link
Copy Markdown
Member Author

Bah, we gotta fix our typing-conformance script so it doesn't display those demotivating ❌ emojis if the only diagnostics removed are optional diagnostics 😆

@astral-sh-bot

astral-sh-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@AlexWaygood

Copy link
Copy Markdown
Member Author

Ummmmm, I have no idea why there's no ecosystem-analyzer comment here, but the uploaded report at https://github.com/astral-sh/ruff/actions/runs/31708813786?pr=27726 says that there's no ecosystem changes

@AlexWaygood
AlexWaygood marked this pull request as ready for review August 13, 2026 14:27
@AlexWaygood
AlexWaygood requested a review from a team as a code owner August 13, 2026 14:27
@astral-sh-bot
astral-sh-bot Bot requested a review from charliermarsh August 13, 2026 14:27
# An instance declaration does not become a class variable without an explicit qualifier.
static_assert(not is_subtype_of(Foo, HasClassVarX))
static_assert(not is_assignable_to(Foo, HasClassVarX))
# TODO: these should pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain whether this is still a TODO? (And, if so, why revert?)

@AlexWaygood
AlexWaygood marked this pull request as draft August 14, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants