Fixed a bug that led to a false positive "reportOverlappingOverload" error when the return type of two overlapping overloads both used a generic return type.

This commit is contained in:
Eric Traut 2022-04-29 20:17:26 -07:00
parent 73a7bca0ba
commit f749e2b0a7
3 changed files with 17 additions and 3 deletions

View File

@ -1787,7 +1787,7 @@ export class Checker extends ParseTreeWalker {
prevReturnType,
/* diag */ undefined,
new TypeVarContext(),
CanAssignFlags.SkipSolveTypeVars
CanAssignFlags.SkipSolveTypeVars | CanAssignFlags.IgnoreTypeVarScope
)
) {
const altNode = this._findNodeForOverload(node, prevOverload);

View File

@ -7,6 +7,7 @@ from typing import (
List,
Literal,
Optional,
Sequence,
Tuple,
Type,
TypeVar,
@ -279,7 +280,6 @@ class ClassA(Generic[_T1]):
class ClassB:
# This should generate an error because the overload is overlapping.
@overload
def __call__(self, f: _T1) -> _T1:
...
@ -317,3 +317,17 @@ class ClassD:
def method1(self, x: Any) -> Any:
...
@overload
def func18(s: Sequence[_T1], extra: Literal[False]) -> list[_T1]: ...
@overload
def func18(s: Sequence[_T1], extra: Literal[True]) -> list[_T1] | tuple[_T1]: ...
@overload
def func18(s: Sequence[_T1], extra: bool) -> list[_T1] | tuple[_T1]: ...
def func18(s: Sequence[_T1], extra: bool) -> list[_T1] | tuple[_T1]:
...

View File

@ -262,7 +262,7 @@ test('Overload5', () => {
configOptions.diagnosticRuleSet.reportOverlappingOverload = 'error';
analysisResults = TestUtils.typeAnalyzeSampleFiles(['overload5.py'], configOptions);
TestUtils.validateResults(analysisResults, 12);
TestUtils.validateResults(analysisResults, 11);
});
test('Overload6', () => {