Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,11 @@ def collect_attributes(self) -> list[DataclassAttribute] | None:
# We will issue an error later.
continue

assert isinstance(node, Var), node
# A ClassVar assigned a class definition, such as a TypedDict,
# can be represented by a TypeInfo rather than a Var. Dataclasses
# ignore ClassVars, so there is no attribute to collect here.
if not isinstance(node, Var):
continue

# x: ClassVar[int] is ignored by dataclasses.
if node.is_classvar:
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-dataclasses.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
[case testClassVarTypedDict]
import dataclasses
from typing import ClassVar, TypedDict

@dataclasses.dataclass
class X:
value: int
TD: ClassVar = TypedDict("TD", {"value": int})

X.TD

[builtins fixtures/tuple.pyi]
[typing fixtures/typing-medium.pyi]

[case testDataclassesBasic]
from dataclasses import dataclass

Expand Down
Loading