Skip to content

Commit

Permalink
Fixed a bug that results in a false positive error when a method defi…
Browse files Browse the repository at this point in the history
…ned within a named tuple is overridden by a subclass. This addresses #7256. (#7259)
  • Loading branch information
erictraut authored Feb 14, 2024
1 parent 2ff6efb commit 4b206e3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
19 changes: 11 additions & 8 deletions packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4783,14 +4783,17 @@ export class Checker extends ParseTreeWalker {
// If the parent class is a named tuple, all instance variables
// (other than dundered ones) are implicitly final.
const decl = localSymbol.getDeclarations()[0];
this._evaluator.addDiagnostic(
DiagnosticRule.reportIncompatibleVariableOverride,
LocMessage.namedTupleEntryRedeclared().format({
name,
className: parentSymbol.classType.details.name,
}),
decl.node
);

if (decl.type === DeclarationType.Variable) {
this._evaluator.addDiagnostic(
DiagnosticRule.reportIncompatibleVariableOverride,
LocMessage.namedTupleEntryRedeclared().format({
name,
className: parentSymbol.classType.details.name,
}),
decl.node
);
}
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/analyzer/sourceFileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class SourceFileInfo {
this._writableData = this._preEditData;
this._preEditData = undefined;

// Some states have changed. Force some of info to be re-calcuated.
// Some states have changed. Force some of info to be re-calculated.
this.sourceFile.dropParseAndBindInfo();
}

Expand Down
6 changes: 6 additions & 0 deletions packages/pyright-internal/src/tests/samples/namedTuple10.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ class Point(NamedTuple):
x: int
y: int

def f(self):
pass


class BadPointWithName(Point):
name: str

# This should generate an error.
x: int

def f(self):
pass

0 comments on commit 4b206e3

Please sign in to comment.