Skip to content

Commit

Permalink
Fixed bug that results in a spurious "overlapping overload" error if …
Browse files Browse the repository at this point in the history
…the second both overloads have an `*args` but the first has one or more additional positional parameters. This addresses #9916. (#9921)
  • Loading branch information
erictraut authored Feb 15, 2025
1 parent 0622bb8 commit cd32784
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26182,6 +26182,7 @@ export function createTypeEvaluator(
const destPositionalCount = destParamDetails.firstKeywordOnlyIndex ?? destParamDetails.params.length;
const srcPositionalCount = srcParamDetails.firstKeywordOnlyIndex ?? srcParamDetails.params.length;
const positionalsToMatch = Math.min(destPositionalCount, srcPositionalCount);
const skippedPosParamIndices: number[] = [];

// Match positional parameters.
for (let paramIndex = 0; paramIndex < positionalsToMatch; paramIndex++) {
Expand All @@ -26197,6 +26198,9 @@ export function createTypeEvaluator(

// Skip over the *args parameter since it's handled separately below.
if (paramIndex === destParamDetails.argsIndex) {
if (!isUnpackedTypeVarTuple(destParamDetails.params[destParamDetails.argsIndex].type)) {
skippedPosParamIndices.push(paramIndex);
}
continue;
}

Expand Down Expand Up @@ -26329,7 +26333,13 @@ export function createTypeEvaluator(
}

if (destPositionalCount < srcPositionalCount && !targetIncludesParamSpec) {
// Add any remaining positional parameter indices to the list that
// need to be validated.
for (let i = destPositionalCount; i < srcPositionalCount; i++) {
skippedPosParamIndices.push(i);
}

for (const i of skippedPosParamIndices) {
// If the dest has an *args parameter, make sure it can accept the remaining
// positional arguments in the source.
if (destParamDetails.argsIndex !== undefined) {
Expand Down
11 changes: 11 additions & 0 deletions packages/pyright-internal/src/tests/samples/overloadOverlap1.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,14 @@ def func32(n: list[NestedList[Any]]) -> list[Any]: ...


def func32(n: Any) -> Any: ...


@overload
def func33(a: int, /, *args: str) -> None: ...


@overload
def func33(*args: str) -> None: ...


def func33(*args: int | str) -> None: ...

0 comments on commit cd32784

Please sign in to comment.