[ty] Promote class-literal types to type in invariant contexts#23872
[ty] Promote class-literal types to type in invariant contexts#23872AlexWaygood wants to merge 1 commit intomainfrom
type in invariant contexts#23872Conversation
type in invariant contexttype in invariant contexts
|
something I did made rustfmt decide it wanted to reformat the entire function (I think a comment placed in exactly the wrong place meant it couldn't format anything in this function before...) |
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 85.29% to 85.30%. The percentage of expected errors that received a diagnostic increased from 78.13% to 78.23%. The number of fully passing files held steady at 64/132. SummaryHow are test cases classified?Each test case represents one expected error annotation or a group of annotations sharing a tag. Counts are per test case, not per diagnostic — multiple diagnostics on the same line count as one. Required annotations (
Test file breakdown1 file altered
True positives added (1)1 diagnostic
True positives changed (6)6 diagnostics
|
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
|
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
6 | 5 | 19 |
unresolved-attribute |
5 | 0 | 9 |
invalid-assignment |
1 | 0 | 1 |
invalid-parameter-default |
1 | 0 | 0 |
invalid-return-type |
1 | 0 | 0 |
not-iterable |
0 | 0 | 1 |
unused-type-ignore-comment |
0 | 1 | 0 |
| Total | 14 | 6 | 30 |
|
|
||
| Type::ClassLiteral(class) => match type_mapping { | ||
| TypeMapping::Promote(PromotionMode::On) => { | ||
| SubclassOfType::from(db, ClassType::NonGeneric(class)) |
There was a problem hiding this comment.
This promotes e.g. int to type[int], not to just type. Which is a reasonable promotion, but I think unlikely to help most invariant cases? It assumes that by [int] you mean list[type[int]], which is still too precise if you later wanted to insert str into the list.
This is a tricky one because type types are already weird. It's hard to say whether you meant a list of callables, or a list of type objects that you want to later use in e.g. isinstance, or what.
There was a problem hiding this comment.
For example, it means this PR still wouldn't help with astral-sh/ty#3013
There was a problem hiding this comment.
This promotes e.g.
inttotype[int], not to justtype.
I know that 😛 this is a draft PR for a reason, I'm playing around with stuff! The PR title is out of date.
the first thing I tried was promoting class-literal types all the way to type, as per the PR description, and it did indeed fix a bunch of false positives, but it also caused a bunch of new ones. So I then tried doing the halfway promotion to a subclass-of type, but now we have a very underwhelming ecosystem report such that I'm not sure it's worth it.
I think we may just have to wait for better bidirectional inference on this one
55301b1 to
4820b87
Compare
4820b87 to
a34e880
Compare
|
I've tried three different kinds of promotion here (recursive promotion to |
Summary
Test Plan