diff --git a/packages/pyright-internal/src/analyzer/dataClasses.ts b/packages/pyright-internal/src/analyzer/dataClasses.ts index b7c705fffd8f..43e772ed273b 100644 --- a/packages/pyright-internal/src/analyzer/dataClasses.ts +++ b/packages/pyright-internal/src/analyzer/dataClasses.ts @@ -396,11 +396,9 @@ export function synthesizeDataClassMethods( const variableSymbol = ClassType.getSymbolTable(classType).get(variableName); namedTupleEntries.add(variableName); - if (variableSymbol?.isClassVar() && !variableSymbol?.isFinalVarInClassBody()) { + if (variableSymbol?.isClassVar()) { // If an ancestor class declared an instance variable but this dataclass // declares a ClassVar, delete the older one from the full data class entries. - // We exclude final variables here because a Final type annotation is implicitly - // considered a ClassVar by the binder, but dataclass rules are different. const index = fullDataClassEntries.findIndex((p) => p.name === variableName); if (index >= 0) { fullDataClassEntries.splice(index, 1); diff --git a/packages/pyright-internal/src/tests/samples/dataclass17.py b/packages/pyright-internal/src/tests/samples/dataclass17.py index 81d64b73e374..1d770129b4b4 100644 --- a/packages/pyright-internal/src/tests/samples/dataclass17.py +++ b/packages/pyright-internal/src/tests/samples/dataclass17.py @@ -33,3 +33,9 @@ class A: # This should generate an error. A.e = 0 + + +@dataclass +class B: + a: ClassVar[Final[int]] = 0 + b: int = 1