-
Notifications
You must be signed in to change notification settings - Fork 771
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
Functions aren't always able to match TypeVar to method argument types #1182
Comments
Thanks for the bug report. This bug looks similar to as this one: #1180. It is very difficult to repro in pyright, but it appears readily in pylance. I'll look into it in more detail. |
I'm pretty sure I've fixed this bug in the pyright source base. @jakebailey, we should double check that the problem no longer appears in pylance when you pull the code over and integrate next time. |
Most recent commit didn't help, unfortunately. |
I'm able to repro the core problem in this bug report. Here's a simplified repro, thanks to @jakebailey: from typing import TypeVar
class A:
def method(self, x: "A") -> "A": ...
class B:
def method(self, x: "B") -> "B": ...
T = TypeVar("T", A, B)
def check(x: T, y: T) -> T:
return x.method(y) Supporting this use case is going to be a challenge. It requires that constraints imposed by a constrained TypeVar need to be distributed across a function call expressions when evaluating the arguments for that call. In the example above, for example, the type of argument expression |
I've added the support for propagating constraints to call arguments when the call portion of a call expression imposes such a constraint. For example, the sample above uses The fix will be included in the next release of pylance. |
Brilliant, thanks! |
This issue has been fixed in version 2021.4.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202143-29-april-2021 |
Environment data
Code Snippet / Additional information
Expected behaviour
Nothing should be underlined.
Both DataFrame and Series have a divide method. Series method accepts a Series and DataFrame method accepts either a DataFrame or a Series.
Actual behaviour
In the
divide_them
function we get for argument pd2:Argument of type "DfSer@divide_them" cannot be assigned to parameter "other" of type "int | float | ndarray | Dict[_str, ndarray] | Sequence[Unknown] | Index[Unknown] | Series[Unknown]" in function "divide"
Similar issues in other functions.
We avoid errors if we explicitly check for both arguments like in divide_them_4.
The text was updated successfully, but these errors were encountered: