Skip to content
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

dev: Appease Pyright 1.1.345's changed type checking of tuple slices #344

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

tsibley
Copy link
Member

@tsibley tsibley commented Jan 11, 2024

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

Checklist

  • Checks pass

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>
@tsibley tsibley merged commit c628033 into master Jan 11, 2024
@tsibley tsibley deleted the trs/appease-type-checker branch January 11, 2024 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant