pylance-release
pylance-release copied to clipboard
Call signature narrowing for overloaded methods/functions
Pylance reports all available overloads for overloaded methods. However, as arguments are provided, some of them can be discarded. Example:
@overload
def f(x: Literal["foo"], foo: int = 2) -> None: ...
@overload
def f(x: Literal["bar"], bar: int = 3) -> None: ...
def f(x: str, *args: int, **kwargs: int) -> None: ...
My expectation is that when entering the first literal string:
f("bar",
that pylance would suggest the call signature of the second overload directly. However, currently, the impossible first overload is still displayed:
Use case
It's a pretty common python pattern to dispatch to different implementations based on the value of some "mode" or "task" parameter. It is also commonly used in __new__
to create one of several classes. This would greatly improve the user experience working with these patterns.
This is the same as https://github.com/microsoft/pylance-release/discussions/4148, and similar to https://github.com/microsoft/pylance-release/issues/4428
Thanks for reporting the issue, this is indeed a dupe of https://github.com/microsoft/pylance-release/discussions/4148. Please upvote the idea if you'd like to see it being supported, thanks!