[ty] Support deferred and recursive type evaluation in NamedTuple(...)#22627
[ty] Support deferred and recursive type evaluation in NamedTuple(...)#22627charliermarsh wants to merge 4 commits intomainfrom
NamedTuple(...)#22627Conversation
Typing conformance resultsNo changes detected ✅ |
|
ea6b849 to
91625e3
Compare
91625e3 to
15648e1
Compare
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-return-type |
0 | 3 | 6 |
invalid-parameter-default |
0 | 0 | 7 |
invalid-argument-type |
0 | 1 | 5 |
invalid-assignment |
0 | 0 | 5 |
possibly-missing-attribute |
0 | 3 | 1 |
invalid-await |
0 | 2 | 0 |
unresolved-attribute |
0 | 0 | 2 |
unused-ignore-comment |
1 | 0 | 0 |
| Total | 1 | 9 | 26 |
|
Thanks @charliermarsh ❤️ There's a lot to like about this PR... but there's also quite a few things I'd do differently. In particular, I don't think it's necessary to defer inference of from typing import NamedTuple
class Foo(NamedTuple("F", [("x", "Foo | None")]):
pass... that's already dealt with by our existing logic on ruff/crates/ty_python_semantic/src/types/infer/builder.rs Lines 3191 to 3201 in 55a174e I've taken a stab at solving this problem myself in #22718, though I want to pull some parts of that PR into standalone changes, since there's some refactoring in there that makes the overall diff a bit confusing at the moment. Overall it ends up being a slightly "messier" diff (there's more code being removed/rewritten rather than simply being added) but it ends up being quite a few LOC less than this PR overall. One problem that both our PRs have, however, is that they both currently have stack overflows on this test case: from typing import NamedTuple
A = NamedTuple("A", [("x", "B | None")])
B = NamedTuple("B", [("x", "C")])
C = NamedTuple("C", [("x", A)])
A(x=C())(your PR only seems to overflow on that snippet after I'm not yet sure how to fix that... |
|
(I did just copy-and-paste some of your tests and code straight from this PR into my PR, so I'll definitely list you as a co-author!) |
|
No worries, we can continue the conversation over there. |
Summary
Closes astral-sh/ty#2528.
Closes astral-sh/ty#2529.