[ty] Avoid storing invalid multi-inference attempts#22062
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
0 | 0 | 81 |
invalid-return-type |
0 | 0 | 2 |
type-assertion-failure |
0 | 0 | 2 |
| Total | 0 | 0 | 85 |
CodSpeed Performance ReportMerging #22062 will degrade performances by 5.31%Comparing Summary
Benchmarks breakdown
Footnotes
|
AlexWaygood
left a comment
There was a problem hiding this comment.
That's a pretty huge improvement in the types we're displaying in our diagnostics 😃
## Summary I missed this in #22062. This avoids exponential runtime in the following snippet: ```py class X1: ... class X2: ... class X3: ... class X4: ... class X5: ... class X6: ... ... def f( x: list[X1 | None] | list[X2 | None] | list[X3 | None] | list[X4 | None] | list[X5 | None] | list[X6 | None] ... ): ... def g[T](x: T) -> list[T]: return [x] def id[T](x: T) -> T: return x f(id(id(id(id(g(X64())))))) ``` Eventually I want to refactor our multi-inference infrastructure (which is currently very brittle) to handle this implicitly, but this is a temporary performance fix until that happens.
Summary
This should make revealed types a little nicer, as well as avoid confusing the constraint solver in some cases (which were showing up in #21930).