-
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
Pyright does not handle overload ambiguity #2521
Comments
The current behavior is intended. We've discussed possibly changing the behavior, but there are downsides to doing so. There are arguably three reasonable behaviors when faced with an ambiguity due to an
If pyright were just a type checker (like mypy), the argument in favor of option 2 would be stronger. However, pyright is not just a type checker. It's also the basis for a language server (pylance). For every pylance user who enables type checking, there are another twenty who do not. The majority of users value completion suggestions over type checking results. An If I were to rank the above options based on type checking alone, I'd say that option 2 is better than 1 (but only slightly so), and option 3 is by far the worst. If I were to rank the above options based on completion suggestions, I'd say that option 3 is best followed by 1, with option 2 by far the worst. The current behavior (1) tries to strike the right balance. For what it's worth, TypeScript also uses option 1. You might argue that we should have different behaviors when type checking is disabled, but we're very reluctant to do this because it creates confusion and inconsistencies when the type information changes depending on whether type errors are reported. Every time we've done this in the past, we've regretted it, so we've established a principle that type evaluations must be the same in all modes. We will likely reconsider this decision periodically as we receive additional feedback, so we appreciate the input. For now I think we're going to stick with the current behavior. The workaround is to avoid the use of |
Hi Eric, thanks for the clarification.
Interesting, i actually wasn't aware of pyright's larger role here. In any case, avoiding
Lastly, this might be slightly off topic but could a proper dedicated unsafe union-type (python/typing#566) change the viability of behavior (3)? |
That's a good point. Yes, I think an However, |
Describe the bug
Pyright currently does not handle overload ambiguity, always defaulting to the first overload in such a situation (see below).
After its report in numpy/numpy#20265 I initially thought this might be a similar issue as python/mypy#11347,
but the fact that it seems to affect all overloaded callables makes it quite a bit more expansive.
To Reproduce
Expected behavior
The return of either
Any
or, depending on the particular overloads, anAny
-parametrized generic.VS Code extension or command-line
pyright
command)The text was updated successfully, but these errors were encountered: