-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Calling with unpacked args f(*args)
selects overload for f()
#3685
Comments
This is apparently due to a recent change in the typeshed stub @overload
def gather(*, return_exceptions: bool = ...) -> Future[tuple[()]]: ... I think pyright is doing the right thing here from a type checking perspective. This overload should probably be moved down to the bottom of the overload list. Feel free to file a bug in the typeshed issue tracker. |
@erictraut This behavior still seems unexpected to me. I fixed my example to provide an overload for the variadic case:
pyright output:
mypy output:
The mypy output is what I would expect - could you explain why in pyright, |
Pyright picks the first overload signature that is compatible with the supplied arguments. The unpack operator expands Both mypy and pyright accept this code. def func1() -> None:
pass
def func2(*args: int) -> None:
func1(*args)
x: Callable[[], None] = func2 So clearly mypy treats In any case, pyright is working as designed here, so I don't consider this a bug. |
Okay, thanks for the explanation. I'll file my issue in the typeshed repo. |
I recently submitted a draft update to the Python typing spec that details how type checkers should evaluate calls to overloaded functions. The proposed spec covers this case, which pyright and mypy previously handled in an inconsistent manner. Assuming the draft is accepted (which I think it will be), type checker behavior will be consistent for this case. And in particular, pyright will now evaluate the code above in the same way as mypy. |
We are seeing new Pyright failures related to the following:
The type checking now incorrectly assumes that
b
is empty, leading to potential errors down the line.To check that this is not an issue with the
asyncio
type stubs I tried the following:Pyright version: 1.1.258
Python version: 3.8.10
The text was updated successfully, but these errors were encountered: