Fixed bug that results in a false negative when determining if a callable type is compatible with another callable type and the first has a *args parameter and the second has a single positional+keyword parameter. This addresses #7937. (#7938)

This commit is contained in:
Eric Traut 2024-05-16 17:44:12 -07:00 committed by GitHub
parent 1f16eb66b5
commit 7699780a0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 46 additions and 1 deletions

View File

@ -25013,6 +25013,23 @@ export function createTypeEvaluator(
) {
canAssign = false;
}
} else if (
destParam.source !== ParameterSource.PositionOnly &&
srcParam.source === ParameterSource.PositionOnly &&
srcParamDetails.kwargsIndex === undefined &&
!srcParamDetails.params.some(
(p) =>
p.source === ParameterSource.KeywordOnly &&
p.param.category === ParameterCategory.Simple &&
p.param.name === destParam.param.name
)
) {
diag?.addMessage(
LocAddendum.namedParamMissingInSource().format({
name: destParam.param.name ?? '',
})
);
canAssign = false;
}
}

View File

@ -331,3 +331,31 @@ def func17(**kwargs: float) -> None: ...
def func17(d: dict[str, float] | None = None, /, **kwargs: float) -> None:
pass
@overload
def func18(a: int) -> int: ...
@overload
def func18(*args: int) -> int: ...
# This should generate an error because the keyword parameter "a" is missing.
def func18(*args: int) -> int: ...
@overload
def func19(a: int) -> int: ...
@overload
def func19(*args: int) -> int: ...
def func19(*args: int, a: int = 1) -> int: ...
@overload
def func20(a: int) -> int: ...
@overload
def func20(*args: int) -> int: ...
def func20(*args: int, **kwargs: int) -> int: ...

View File

@ -58,7 +58,7 @@ test('Overload6', () => {
test('Overload7', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['overload7.py']);
TestUtils.validateResults(analysisResults, 6);
TestUtils.validateResults(analysisResults, 7);
});
test('Overload8', () => {