Coding 2023-05-13
Okay, here we are, looking at the saltate plugin again. The key thing here is, I need to understand exactly how the "proper types" in Mypy work, because there are a lot of them, and what I'm doing currently is not quite right. I need to work out how to activate each type of proper type, the correct behavior for it, and to devise corresponding tests.
Let's see...
- TypeVarLikeType
- TypeVarType
- ParamSpecType
- TypeVarTupleType
- I believe these should be treated as either their upper bound, or Any. Maybe fail?
- UnboundType I'm not sure what to do with this if it shows up.
- CallableArgument Should not show up.
- TypeList Should not show up.
- UnpackType Should not show up.
- AnyType Should already be handled.
- UninhabitedType Should be treated as Any. Maybe can obtain using NoReturn?
- NoneType It's None. Should fail.
- ErasedType Not sure how to hit this.
- DeletedType I don't have an intuition for how this should interact with any of the plugin. Should probably just fail.
- Instance I'm trying to handle this already.
- FunctionLike: CallableType and Overloaded These should fail.
- Parameters Probably should not show up.
- TupleType Should fail.
- TypedDictType Should fail.
- RawExpressionType Should not show up.
- LiteralType Should fail.
- UnionType Needs special handling. Every argument of a union needs to be transformed recursively.
- PartialType If it shows up, the correct action is... probably complicated? Like okay, from a "do the types match" perspective, the correct action is to replace the placeholders with Any. When it comes to the typ argument, this shouldn't show up, so as inst, when the types match, we need something like an attrs class with a field of type T | None. I think that makes a PartialType.
- EllipsisType Should not show up.
- TypeType Must be handled, with specific cases for Instance, AnyType, TypeVarType, TupleType, NoneType, CallableType.
- PlaceholderType Should not show up?
So, to summarize:
typ argument must handle TypeType and UnionType of TypeType. Within the TypeType, it needs special handling for AnyType and Instance. Maybe convert TypeVarType to its upper bound, but probably don't. Actually, there's even more subtlety here, bleh. I kind of hope a constrained typevar just gets checked with the concrete values so I don't have to think about it? Everything else should fail and coerce to Any.
inst argument needs to handle the same types as typ, and maybe also PartialType?
From this, we see that the plugin is mostly done, but it still needs work, mostly to cover the union cases. I'll get to that whenever. I'll at least write a test to see how messed up it all is.
Okay, it's definitely messed up, and I'm not currently up for fixing it, so, whenever. For now...
Good night.