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] Add heterogeneous tuple type variant #13295

Merged
merged 8 commits into from
Sep 10, 2024
Merged

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Sep 9, 2024

Summary

This PR adds a new Type variant called TupleType which is used for heterogeneous elements.

Display notes

  • For an empty tuple, I'm using tuple[()] as described in the docs: https://docs.python.org/3/library/typing.html#annotating-tuples
  • For nested elements, it'll use the literal type instead of builtin type unlike Pyright which does tuple[Literal[1], tuple[int, int]] instead of tuple[Literal[1], tuple[Literal[2], Literal[3]]]. Also, mypy would give tuple[builtins.int, builtins.int] instead of tuple[Literal[1], Literal[2]]

Test Plan

Update test case to account for the display change and add cases for multiple elements and nested tuple elements.

@dhruvmanila dhruvmanila added the red-knot Multi-file analysis & type inference label Sep 9, 2024
@dhruvmanila dhruvmanila marked this pull request as ready for review September 9, 2024 21:17
Copy link
Contributor

github-actions bot commented Sep 9, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you!

crates/red_knot_python_semantic/src/types.rs Outdated Show resolved Hide resolved
crates/red_knot_python_semantic/src/types.rs Outdated Show resolved Hide resolved
crates/red_knot_python_semantic/src/types.rs Outdated Show resolved Hide resolved
crates/red_knot_python_semantic/src/types/infer.rs Outdated Show resolved Hide resolved
crates/red_knot_python_semantic/src/types/infer.rs Outdated Show resolved Hide resolved
dhruvmanila and others added 2 commits September 10, 2024 13:25
- Rename `TupleLiteral*` -> `Tuple*`
- Move some TODO comments
- Use `Box<[...]>` instead of `Vec<...>`
Co-authored-by: Carl Meyer <carl@astral.sh>
@dhruvmanila dhruvmanila enabled auto-merge (squash) September 10, 2024 17:27
@dhruvmanila dhruvmanila merged commit b7cef6c into main Sep 10, 2024
18 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/tuple-type branch September 10, 2024 17:54
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!!

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 this pull request may close these issues.

3 participants