Skip to content

Commit

Permalink
Fixed a bug that led to a false negative when a subclass overrides a …
Browse files Browse the repository at this point in the history
…parent class with an overloaded method in an incompatible manner. This addresses #6382. (#6396)
  • Loading branch information
erictraut authored Nov 9, 2023
1 parent dbd9976 commit de7d732
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24878,7 +24878,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
}

if (matchIndex < 0) {
continue;
break;
}

if (matchIndex < previousMatchIndex) {
Expand Down
28 changes: 28 additions & 0 deletions packages/pyright-internal/src/tests/samples/methodOverride6.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,31 @@ def function(self: Parent4[int], a: int) -> float:

def function(self, a: int | None = None) -> float:
return 0.0


class Parent5:
@overload
def m1(self, x: int) -> int:
...

@overload
def m1(self, x: str) -> str:
...

def m1(self, x: int | str) -> int | str:
...


class Parent5_1(Parent5):
@overload
def m1(self, x: bytes) -> bytes:
...

@overload
def m1(self, x: str) -> str:
...

# This should generate an error because the overloads are
# incompatible
def m1(self, x: bytes | str) -> bytes | str:
...
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/typeEvaluator3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ test('MethodOverride6', () => {

configOptions.diagnosticRuleSet.reportIncompatibleMethodOverride = 'error';
const analysisResults2 = TestUtils.typeAnalyzeSampleFiles(['methodOverride6.py'], configOptions);
TestUtils.validateResults(analysisResults2, 2);
TestUtils.validateResults(analysisResults2, 3);
});

test('Enum1', () => {
Expand Down

0 comments on commit de7d732

Please sign in to comment.