[ty] Implement disjointness for TypedDicts#22044
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
| # TODO: T can't be compatible with both `int` and `bool` at the same time, so these types should be | ||
| # disjoint, regardless of the materialization of `T`. |
There was a problem hiding this comment.
Is this sort of "one dynamic type winds up in multiple fields" situation ever something we reason about? Is there a name for this?
There was a problem hiding this comment.
hmm, yeah, this is pretty interesting. No, I haven't come across this problem before, but thinking about it, it must exist for other generic types in our model too. I wouldn't worry about it too much right now, but it could be worth opening a followup issue to discuss it.
|
CodSpeed Performance ReportMerging #22044 will improve performances by 70.52%Comparing Summary
Benchmarks breakdown
Footnotes
|
Clippy and Cargo want very different things here. Clippy demands that the numbered list is indented, but that makes Cargo think it's Rust code and start trying to compile it. I don't know how to make them both happy, so I'm making it a regular `//` comment block instead of an actual `///` doc comment, which seems to shut them both up...
TypedDictType::is_disjoint_from_impl
AlexWaygood
left a comment
There was a problem hiding this comment.
This looks great!! Really good job
| # TODO: T can't be compatible with both `int` and `bool` at the same time, so these types should be | ||
| # disjoint, regardless of the materialization of `T`. |
There was a problem hiding this comment.
hmm, yeah, this is pretty interesting. No, I haven't come across this problem before, but thinking about it, it must exist for other generic types in our model too. I wouldn't worry about it too much right now, but it could be worth opening a followup issue to discuss it.
| // 2c. If both sides are immutable, and their types are disjoint. (Because the type in `C` | ||
| // must be assignable to both.) | ||
| // | ||
| // TODO: Adding support for `closed` and `extra_items` will complicate this. |
|
This mypy_primer hit is in fact a new false positive: + openlibrary/plugins/openlibrary/lists.py:89:19: error[invalid-key] Unknown key "key" for TypedDict `AnnotatedSeedDict`: Unknown key "key"Previously the type of Edit: This is mistaken, see the next comment. |
|
Hmm, actually my comment above is mistaken. |
This is a preliminary step to tagged union narrowing for
TypedDict: astral-sh/ty#1479