-
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
TypeIs[]
incorrectly narrows tuple with known length
#8554
Comments
Thanks for the bug report. I view this as two separate issues. First, pyright is currently producing incorrect narrowed types in this case. The resulting types are overly narrow or just plain wrong. I consider that a bug, and it should be fixed. For comparison, mypy is also producing incorrect narrowed types in this case. I've filed a bug. I've prepared a fix for the bug. With this fix in place, pyright no longer produces incorrect (too narrow or nonsensical) narrowed types, but it doesn't produce the optimal types that you are hoping to see here. Instead, it refrains from narrowing the type or produces types that are wider than possible. The I consider this second part an enhancement request. Producing optimal types in this case is actually quite tricky because the type checker must effectively compute the intersection between two tuple types, and tuple types can be quite complicated. For example, how would one compute the (simplified) intersection of |
…used in conjunction with `TypeIs`. This addresses #8554.
This is addressed in pyright 1.1.374. |
Reproducible example (playground):
Yet it is able to do a better job when
args
's length is unknown (playground):A similar error happens when a
TypeVar
is used (playground), regardless of length:The text was updated successfully, but these errors were encountered: