[ty] bidirectional type inference using function return type annotations#20528
[ty] bidirectional type inference using function return type annotations#20528ibraheemdev merged 33 commits intoastral-sh:mainfrom
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.
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 <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
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.