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

[red-knot] Compare expression inference - Union #13779

Closed
Tracked by #13618
sharkdp opened this issue Oct 16, 2024 · 0 comments · Fixed by #13781
Closed
Tracked by #13618

[red-knot] Compare expression inference - Union #13779

sharkdp opened this issue Oct 16, 2024 · 0 comments · Fixed by #13781
Assignees
Labels
red-knot Multi-file analysis & type inference

Comments

@sharkdp
Copy link
Contributor

sharkdp commented Oct 16, 2024

Part of #13618: infer types for expressions x > y, x == y, etc. where x and/or y are of union type.

@sharkdp sharkdp changed the title Union [red-knot] Compare expression inference - Union Oct 16, 2024
@sharkdp sharkdp added the red-knot Multi-file analysis & type inference label Oct 16, 2024
@sharkdp sharkdp self-assigned this Oct 16, 2024
sharkdp added a commit that referenced this issue Oct 17, 2024
## Summary

Add type inference for comparisons involving union types. For example:
```py
one_or_two = 1 if flag else 2

reveal_type(one_or_two <= 2)  # revealed: Literal[True]
reveal_type(one_or_two <= 1)  # revealed: bool
reveal_type(one_or_two <= 0)  # revealed: Literal[False]
```

closes #13779

## Test Plan

See `resources/mdtest/comparison/unions.md`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant