-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[ty] Understand homogeneous tuple annotations #17998
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
Conversation
|
CodSpeed Performance ReportMerging #17998 will not alter performanceComparing Summary
|
2aca14d
to
116f0b6
Compare
116f0b6
to
69ea8ae
Compare
69ea8ae
to
336e137
Compare
Looking at the primer results, it seems like we might want assignability of homogenous tuple to Sequence before we land this? |
I added tests that demonstrate that we do understand a heterogeneous tuples as being subtypes of |
Yeah I was just reaching the same conclusion 👍 |
I added some more tests, just for safety 😆 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent!
@@ -17,6 +17,7 @@ def _(x: tuple[int, str], y: tuple[None, tuple[int]]): | |||
|
|||
```py | |||
def _(x: tuple[int, ...], y: tuple[str, ...]): | |||
reveal_type(x + y) # revealed: @Todo(full tuple[...] support) | |||
reveal_type(x + (1, 2)) # revealed: @Todo(full tuple[...] support) | |||
# TODO: should be `tuple[int | str, ...]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any insight into what we are missing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really... there's so many generics fixes happening at once, though, that I feel like I'm sort-of losing track 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's fine, not a blocker here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crates/ty_python_semantic/resources/mdtest/type_properties/is_fully_static.md
Show resolved
Hide resolved
c10a1c9
to
f65958a
Compare
…eepish * origin/main: [ty] Understand homogeneous tuple annotations (#17998)
…eep-dish * origin/main: [ty] Infer parameter specializations of generic aliases (#18021) [ty] Understand homogeneous tuple annotations (#17998) [ty] Induct into instances and subclasses when finding and applying generics (#18052) [ty] Allow classes to inherit from `type[Any]` or `type[Unknown]` (#18060) [ty] Allow a class to inherit from an intersection if the intersection contains a dynamic type and the intersection is not disjoint from `type` (#18055) [ty] Narrowing for `hasattr()` (#18053) Update reference documentation for `--python-version` (#18056) [`flake8-bugbear`] Ignore `B028` if `skip_file_prefixes` is present (#18047) [`airflow`] Apply try-catch guard to all AIR3 rules (`AIR3`) (#17887) [`pylint`] add fix safety section (`PLW3301`) (#17878) Update `--python` to accept paths to executables in virtual environments (#17954) [`pylint`] add fix safety section (`PLE4703`) (#17824) [`ruff`] Implement a recursive check for `RUF060` (#17976) [`flake8-use-pathlib`] `PTH*` suppress diagnostic for all `os.*` functions that have the `dir_fd` parameter (#17968) [`refurb`] Mark autofix as safe only for number literals in `FURB116` (#17692) [`flake8-simplify`] Fix `SIM905` autofix for `rsplit` creating a reversed list literal (#18045) Avoid initializing progress bars early (#18049)
Summary
With this PR,
ty
now understands thattuple[int, ...]
should be understood as "take the generictuple
class in typeshed, and specialize it with a singleint
type argument".Ironically, more code had to change in our exception-handling logic than in our type-expression-parsing logic here, in order to prevent regressions in our tests.
This PR is stacked on top of #18052, as without the fixes there this PR causes a prohibitive number of false-positive errors.
Closes astral-sh/ty#237
Test Plan
Existing mdtests updated.