-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Incorrect error on specific order of multi-pattern case
clause
#6008
Comments
Actually, you can see this without placeholders if you have a clause like |
Thanks for the bug report. This is due to a small inconsistency between the Python type system and the Python runtime. The print(isinstance(True, int)) # True In the type system, according to PEP 484, print(isinstance(1, float)) # False In general, when there's a difference between the type system and the runtime, pyright honors the type system. That's why you're seeing the behavior here. I'll need to think more about whether this is something we might want to address. I'm reluctant to fix just this case but leave all other cases where pyright honors the type system over the runtime. If this change is made, it would need to be made everywhere, which would be a pretty significant change with lots of churn. |
…ased in PEP 484 as "promotion types". The new logic now properly models the runtime behavior for `isinstance` and class pattern matching when used with these promotion types. This addresses #6008.
…ased in PEP 484 as "promotion types". The new logic now properly models the runtime behavior for `isinstance` and class pattern matching when used with these promotion types. This addresses #6008.
This will be addressed in the next release. |
This is addressed in pyright 1.1.329, which I just published. It will also be included in a future release of pylance. |
I noticed a difference in the ordering between a match of
str(v) | bool(v) | float(v)
andstr(v) | float(v) | bool(v)
. The code is below.Pyright incorrectly issues errors on code in the last match.
Admittedly1, this only happens when you write useless code like
str(v) | float(v) | bool(v)
, or more-realistically, the still-uselessstr(_) | float(_) | bool(_)
. If you remove the binding variable from these, the error goes away entirely.VS Code extension or command-line
I'm running in VS Code via Pylance 2023.9.20
1Be patient with me, this is my second time using pattern matching. 😅
The text was updated successfully, but these errors were encountered: