dev: Appease Pyright 1.1.345's changed type checking of tuple slices #344
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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
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
Checklist