-
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
Tuple size is lost while it can be deduced #6958
Comments
I've also run into this where a tuple typed This was fine with 1.1.344. |
A slice like x[0:2] may evaluate to ('a',) or ('a', 'b',) depending on the length of x. Pyright changed its checking of this slice behaviour for tuples in 1.1.345 (released 4 days ago)¹, which started raising issues with this code in CI. While we humans know that the sockaddr tuples here always have at least two elements, Pyright does not. I think Pyright could do better here as it knows the type of sockaddr is Tuple[str, int] | Tuple[str, int, int, int] and thus I think should be able to know for sure the type of a 0:2 slice. Instead, it evaluates the slice type to an ambiguous Tuple[str | int, ...] which is incompatible with the declared return type. I went to report this behaviour regression, but someone beat me to it: <microsoft/pyright#6958>. ¹ <https://github.com/microsoft/pyright/releases/tag/1.1.345>
A slice like x[0:2] may evaluate to ('a',) or ('a', 'b',) depending on the length of x. Pyright changed its checking of this slice behaviour for tuples in 1.1.345 (released 4 days ago)¹, which started raising issues with this code in CI. While we humans know that the sockaddr tuples here always have at least two elements, Pyright does not. I think Pyright could do better here as it knows the type of sockaddr is Tuple[str, int] | Tuple[str, int, int, int] and thus I think should be able to know for sure the type of a 0:2 slice. Instead, it evaluates the slice type to an ambiguous Tuple[str | int, ...] which is incompatible with our declared return type. I went to report this behaviour regression, but someone's already beat me to it.² ¹ <https://github.com/microsoft/pyright/releases/tag/1.1.345> ² <microsoft/pyright#6958>
…d tuple if the end of the slice is the same as the tuple length (off-by-one error). This addresses #6958.
Thanks for the bug report. This was an off-by-one error in my logic — and a hole in (what was otherwise an extensive) test suite. This will be fixed in the next release. |
This is included in pyright 1.1.346, which I just published. It will also be included in a future release of pylance. |
Describe the bug
Tuple size is lost while it can be deduced.
Code or Screenshots
VS Code extension or command-line
> pyright --version pyright 1.1.345
The text was updated successfully, but these errors were encountered: