Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug that leads to incorrect evaluations when a ClassVar and `… #9553

Merged
merged 1 commit into from
Dec 6, 2024
Merged
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
4 changes: 1 addition & 3 deletions packages/pyright-internal/src/analyzer/dataClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions packages/pyright-internal/src/tests/samples/dataclass17.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading