List and other invariant types should behave covariantly on runtime typechecking
For runtime typechecking deep_type is used to determine the PEP 484 type of a given object. Then is_subtype is used to detect if the type is acceptable. E.g. [2] is considered List[int] by deep_type although it could also be List[float] or List[Union[int, whatever]].
Solution idea:
Widen the use of Empty which is currently used to handle [] and {}, etc.
It would be renamed to Sampled or so and serve as a marker type for is_subtype to check its contained type, e.g. Sampled[List[int]] in covariant manner even if it is actually invariant.
Sounds cool, thank you!
I wonder if this Sampled[] and Empty[] things should be visible in TypeWarning printout when actual type mismatch occurs.
Probably they are better to be removed at printing to not confuse the user.
Yes that's right. Or at least invisible unless some debug flag is set. I would cure this in type_str. However this won't fix before Python 3.7 compatibility is achieved because it requires some broader restructuring. I have rather limited capacity to tackle these bigger changes.