-
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
Type annotation error for generic list that includes union #1526
Comments
Why are you using a type variable in this case? Do you mean to use a union type? NUM_T = Union[int, float] or T = TypeVar("T")
LIST_T = list[T | list[T]]
NUM_T = Union[LIST_T[int], LIST_T[float]] |
@erictraut It's a fabricated example from a larger piece of code whose type annotation may look like |
This will be fixed in the next release. I've improved the heuristics for type matching when the source and destination types are both unions and invariance is enforced. The rules for matching in this case are not well defined and can be ambiguous in some cases where generics are involved in the destination type, but I've improved the heuristics to work in more cases including the one above. |
This issue has been fixed in version 2021.7.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202173-14-july-2021 |
Environment data
Code Snippet / Additional information
Expected behaviour
No error.
Actual behaviour
Error shown on line 14:
The text was updated successfully, but these errors were encountered: