Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified the overload call evaluation logic to conform with the new p… #9760

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9432,7 +9432,7 @@ export function createTypeEvaluator(

// Start by evaluating the types of the arguments without any expected
// type. Also, filter the list of overloads based on the number of
// positional and named arguments that are present. We do all of this
// positional and keyword arguments that are present. We do all of this
// speculatively because we don't want to record any types in the type
// cache or record any diagnostics at this stage.
useSpeculativeMode(speculativeNode, () => {
Expand Down Expand Up @@ -10864,10 +10864,6 @@ export function createTypeEvaluator(
errorNode,
/* emitNotIterableError */ false
)?.type;

if (paramInfo.param.category !== ParamCategory.ArgsList) {
matchedUnpackedListOfUnknownLength = true;
}
}

const funcArg: Arg | undefined = listElementType
Expand Down
38 changes: 24 additions & 14 deletions packages/pyright-internal/src/tests/samples/overloadCall5.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
# This should generate an error because this overload overlaps
# with the third one and returns a different type.
@overload
def func1(__iter1: Iterable[_T1]) -> Tuple[_T1]:
...
def func1(__iter1: Iterable[_T1]) -> Tuple[_T1]: ...


@overload
def func1(__iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> Tuple[_T1, _T2]:
...
def func1(__iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> Tuple[_T1, _T2]: ...


@overload
def func1(*iterables: Iterable[_T1]) -> float:
...
def func1(*iterables: Iterable[_T1]) -> float: ...


def func1(*iterables: Iterable[_T1 | _T2]) -> Tuple[_T1 | _T2, ...] | float:
...
def func1(*iterables: Iterable[_T1 | _T2]) -> Tuple[_T1 | _T2, ...] | float: ...


def test1(x: Iterable[int]):
Expand All @@ -48,18 +44,15 @@ def test1(x: Iterable[int]):


@overload
def func2() -> tuple[()]:
...
def func2() -> tuple[()]: ...


@overload
def func2(x: int, /) -> tuple[int]:
...
def func2(x: int, /) -> tuple[int]: ...


@overload
def func2(*x: int) -> tuple[int, ...]:
...
def func2(*x: int) -> tuple[int, ...]: ...


def func2(*x: int) -> tuple[int, ...]:
Expand All @@ -70,3 +63,20 @@ def func2(*x: int) -> tuple[int, ...]:
reveal_type(func2(1), expected_text="tuple[int]")
reveal_type(func2(1, 2), expected_text="tuple[int, ...]")
reveal_type(func2(*[1, 2, 3]), expected_text="tuple[int, ...]")


@overload
def func3(x: int, /) -> str: ...


@overload
def func3(x: int, y: int, /, *args: int) -> int: ...


def func3(*args: int) -> int | str:
return 1


def test3(v: list[int]) -> None:
r = func3(*v)
reveal_type(r, expected_text="int")
Loading