Open Stewori opened 4 years ago
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.
For runtime typechecking
deep_type
is used to determine the PEP 484 type of a given object. Thenis_subtype
is used to detect if the type is acceptable. E.g.[2]
is consideredList[int]
bydeep_type
although it could also beList[float]
orList[Union[int, whatever]]
.Solution idea: Widen the use of
Empty
which is currently used to handle[]
and{}
, etc. It would be renamed toSampled
or so and serve as a marker type foris_subtype
to check its contained type, e.g.Sampled[List[int]]
in covariant manner even if it is actually invariant.