[ty] Fix overloaded callable assignability for unary Callable targets#23277
Conversation
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 84.99% to 85.17%. The percentage of expected errors that received a diagnostic held steady at 75.25%. Summary
False positives removedDetails
|
Memory usage reportMemory usage unchanged ✅ |
Merging this PR will not alter performance
Comparing Footnotes
|
|
4cbba88 to
a018f28
Compare
a018f28 to
85da64d
Compare
|
primer results look good overall. From my review, the remaining diffs are either intended behavior changes or primer flakiness and I couldn’t reproduce a stable new regression attributable to this PR. (I did find real regressions earlier in development but those have been addressed) |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
0 | 3 | 0 |
invalid-method-override |
0 | 3 | 0 |
unresolved-attribute |
1 | 0 | 0 |
| Total | 1 | 6 | 0 |
|
@dcreager It would be great if you could review this. I'd love to continue to work on dataclass converters to improve our typing conformance results in that area, but this issue is blocking progress. Not very high priority, though. |
crates/ty_python_semantic/resources/mdtest/generics/legacy/callables.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
It can be onerous, but I prefer for all of the new tests in legacy to have analogues in pep695. We've definitely encountered subtle bugs that stem from how we treat those separately in some cases.
There was a problem hiding this comment.
Done. I copied the generics-related tests into pep695 to test the other typevar syntax. The first few tests were not related to generics at all, so I moved those into annotations/callable.md
| relation: TypeRelation<'db>, | ||
| ) -> Option<ConstraintSet<'db>> { | ||
| let other_parameter_type = | ||
| Self::single_required_positional_parameter_type(other_signature)?; |
There was a problem hiding this comment.
Given this usage, I can see why you put these methods here instead of on the types that they take in. If you want to emphasize that those are helpers that are only needed for this method, an alternative formulation that we've used is to declare them as closures inside this method body:
let single_require_positional_parameter_type = |signature| {
...
};
let is_unary_overload_aggregate_candidate_type = |ty| {
// note that you probably won't need `db` as a param since a
// closure can access its surrounding scope
...
};
Sorry I couldn't get to it (currently at work), I saw you handled everything! Thanks a lot for the review and for your work :) |
Summary
Fixes astral-sh/ty#2546
Improves assignability checking from overloaded callables to a single
Callable[...]target with an explicit union parameter domain.Previously, this was handled with per-overload
when_anychecks. This PR replaces that with an aggregate probe over the overload set that:The aggregate probe is accept-only ie. if it isn't definitively satisfied, we fall back to the existing
when_anybehavior. This change is intentionally scoped to unary targets with explicit union domains and excludes dynamic/typevar candidates. Generaln > 1overload-set assignability is a way larger problem left for later.Test Plan
Callable[[T], T]under union-constrained inference.overloaded_converter,ConverterClass) with an explicit TODO expectation for the still unhandledconverter=dictcase.