mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
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:
parent
1f16eb66b5
commit
7699780a0a
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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: ...
|
||||
|
@ -58,7 +58,7 @@ test('Overload6', () => {
|
||||
|
||||
test('Overload7', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['overload7.py']);
|
||||
TestUtils.validateResults(analysisResults, 6);
|
||||
TestUtils.validateResults(analysisResults, 7);
|
||||
});
|
||||
|
||||
test('Overload8', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user