Skip to content

Commit

Permalink
Fixed bug that results in a false negative when determining if a call…
Browse files Browse the repository at this point in the history
…able 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)
  • Loading branch information
erictraut authored May 17, 2024
1 parent 1f16eb6 commit 7699780
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
28 changes: 28 additions & 0 deletions packages/pyright-internal/src/tests/samples/overload7.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/typeEvaluator6.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test('Overload6', () => {

test('Overload7', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['overload7.py']);
TestUtils.validateResults(analysisResults, 6);
TestUtils.validateResults(analysisResults, 7);
});

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

0 comments on commit 7699780

Please sign in to comment.