fix(dataclasses): skip non-Var ClassVars - #21916
Open
daleselaji-dev wants to merge 1 commit into
Open
Conversation
daleselaji-dev
marked this pull request as ready for review
September 1, 2026 02:55
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Mypy reports an
INTERNAL ERRORwhen a dataclass contains aClassVarassigned to a functionalTypedDictdefinition. The combination ofdataclass,ClassVar, andTypedDictshould be valid, but the dataclass plugin crashes during semantic analysis.Root Cause
The dataclass plugin assumes every annotated assignment symbol is a
Var. AClassVarassigned a class definition can instead be represented as aTypeInfo, causingcollect_attributes()to hit an assertion before it can apply the normal ClassVar exclusion.Solution
Skip non-
Varsymbols during dataclass attribute collection. Dataclasses ignore ClassVars, so a class-definition symbol has no instance attribute to collect.Changes
Varassertion with a narrow non-Varguard.check-dataclasses.testregression coveringClassVar = TypedDict(...).Testing
deda499: the supplied reproducer failed withINTERNAL ERROR.Success: no issues found in 1 source file.testClassVarTypedDictpassed.check-dataclasses.test: 151 passed.git diff --check: passed.Compatibility/Risk
This preserves existing handling for
Var,TypeAlias, andDecoratorsymbols. It only avoids collecting a non-Var symbol that dataclasses would ignore, with no public API or runtime behavior change.Notes for Reviewer
The regression uses the same minimal shape reported in #21915 and exercises the plugin through mypy's standard semantic-analysis test harness. The guard is intentionally limited to the attribute-collection boundary.
Linked Issue
Fixes #21915