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

Subexpression type narrowing for match statements #4971

Closed
erictraut opened this issue Apr 18, 2023 · 2 comments
Closed

Subexpression type narrowing for match statements #4971

erictraut opened this issue Apr 18, 2023 · 2 comments
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request

Comments

@erictraut
Copy link
Collaborator

Currently, pyright narrows only the subject expression of a match statement. However, there are cases where a subject expression contains a subexpression that could also be narrowed, at least in theory.

Likewise, expressions that utilize the subject as a subexpression could be narrowed, in theory.

I don't yet know if either of these can be implemented in a way that is computationally feasible, but it's worth investigating.

@erictraut erictraut added the enhancement request New feature or request label Apr 18, 2023
erictraut pushed a commit that referenced this issue Apr 19, 2023
…ce pattern matching when the subject is a tuple of known length. In cases where the pattern narrows one tuple entry in the positive case, we can eliminate that subtype in the negative case. This addresses part of #4971.
erictraut pushed a commit that referenced this issue Apr 19, 2023
…ct is a tuple expression and one of the entries is a subexpression that is later used in a case statement block. This addresses part of #4971.
@erictraut
Copy link
Collaborator Author

I've addressed the first three cases where the subject expression contains a subexpression that can also be narrowed.

The last case is quite different, and I'm not convinced it's worth implementing at this time. It's something that we could consider in the future.

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Apr 19, 2023
@erictraut
Copy link
Collaborator Author

This is addressed in pyright 1.1.304, which is now published. It will also be included in a future release of pylance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant