-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] bidirectional type inference using function return type annotations #20528
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
…e of expressions in return statements
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
…ith `is_disjoint_from` (#20538) ## Summary I found this bug while working on #20528. The minimum reproducible code is: ```python from __future__ import annotations from typing import NamedTuple from ty_extensions import is_disjoint_from, static_assert class Path(NamedTuple): prev: Path | None key: str static_assert(not is_disjoint_from(Path, Path)) ``` A stack overflow occurs when a nominal instance type inherits from `NamedTuple` and is defined recursively. This PR fixes this bug. ## Test Plan mdtest updated
d899f83 to
2d882b3
Compare
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
12 | 15 | 16 |
invalid-return-type |
4 | 11 | 26 |
missing-typed-dict-key |
11 | 0 | 0 |
invalid-key |
3 | 0 | 0 |
no-matching-overload |
3 | 0 | 0 |
possibly-missing-attribute |
1 | 0 | 0 |
unused-ignore-comment |
1 | 0 | 0 |
| Total | 35 | 26 | 42 |
2d882b3 to
ef75f0a
Compare
AlexWaygood
left a comment
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.
This looks pretty good to me! Some small comments below. @dcreager and/or @ibraheemdev will probably be better reviewers, though; I haven't done much work on our bidirectional inference yet
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
25c8ffc to
0249ba2
Compare
…iteral::raw_signature`
CodSpeed Performance ReportMerging #20528 will not alter performanceComparing Summary
Footnotes
|
…verloadLiteral::raw_signature`" This reverts commit 9507d72.
crates/ty_python_semantic/resources/mdtest/generics/legacy/functions.md
Outdated
Show resolved
Hide resolved
|
I think I addressed all review comments. codspeed reports a slight performance regression, but for the same reason as #20635, I believe it is difficult to avoid this. The ecosystem reports are generally good, some false positive errors are due to TODOs in |
|
I think this might need minor updating now that I merged #20806 (since it should fix a test TODO added in that PR)? @ibraheemdev feel free to merge this if it looks ready to you. |
|
This looks great, thanks. |
Summary
Implements bidirectional type inference using function return type annotations.
This PR was originally proposed to solve astral-sh/ty#1167, but this does not fully resolve it on its own.
Additionally, I believe we need to allow dataclasses to generate their own
__new__methods, use constructor return types for inference, and a mechanism to discard type narrowing like& ~AlwaysFalsyif necessary (at a more general level than this PR).Test Plan
mdtest/bidirectional.mdis added.