[red-knot] Consolidate all gradual types into single Type variant#15386
[red-knot] Consolidate all gradual types into single Type variant#15386
Conversation
sharkdp
left a comment
There was a problem hiding this comment.
I like it! (haven't reviewed each and every change, but I guess it's more or less mechanical)
|
|
Brilliant idea! Is it possibly worth calling the variant and struct |
|
Also: all roads lead to Rome |
dcreager
left a comment
There was a problem hiding this comment.
Brilliant idea! Is it possibly worth calling the variant and struct
Type::GradualandGradualTyperather thanType::AnyandAnyType?Type::Any(AnyType::Unknown)reads a bit strangely to me
Done
dcreager
left a comment
There was a problem hiding this comment.
but I guess it's more or less mechanical
That is a good callout. I did try to make this a pure refactoring. For instance, there are a couple of places where we were doing something only for a Todo, but not for Any or Unknown. Instead of inspecting and possibly changing those in this PR, I've left them as-is so that this PR does not combine a refactoring with a logic change.
| todo @ Type::Todo(_) => return Ok(todo), | ||
| todo @ Type::Any(AnyType::Todo(_)) => return Ok(todo), |
* main: [red-knot] Move `UnionBuilder` tests to Markdown (#15374)
Co-authored-by: Alex Waygood <[email protected]>
carljm
left a comment
There was a problem hiding this comment.
This makes handling these in match statements so much nicer!
| @@ -1085,9 +1082,16 @@ impl<'db> Type<'db> { | |||
| pub(crate) fn is_same_gradual_form(self, other: Type<'db>) -> bool { | |||
There was a problem hiding this comment.
Side note on seeing this method, wondering why we need it, and going to look: I wonder if maybe we shouldn't allow Any/Unknown/Todo to coexist in the same union/intersection, and instead should just define a hierarchy of preference, e.g. Todo takes top priority, Any second, and Unknown third?
Definitely not something for this PR, just musing.
Co-authored-by: Carl Meyer <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
Prompted by astral-sh/ty#222:
The thought here is that most places want to treat
Any,Unknown, andTodoidentically. So this PR simplifies things by having a singleType::Anyvariant, and moves the provenance part into a newAnyTypetype. If you need to treat e.g.Tododifferently, you still can by pattern-matching into theAnyType. But if you don't, you can just useType::Any(_).(This would also allow us to (more easily) distinguish "unknown via an unannotated value" from "unknown because of a typing error" should we want to do that in the future)