I just discovered this thread (I wish I could find it earlier…). I was proposing something similar a few days ago under the “idea” topic: run-time type checking using parameterized types.
I also created a working implementation “rttc” for it and published it on GitHub and PyPi.
I am wondering if the proposed is_assignable() is somewhat analogous to type_check(), i.e. how it behaves for the following cases?
-
Nested types
is_assignable([1], list[int]) # True? -
Templated class instances
class C[T]: x: T is_assignable(C[int](), C[float]) # False?
P.S. I encountered some difficulties during the implementation of
rttc. Namely (1) the timing oforig_classavailability and (2) some issues with__annotation__which does not include parent classes’ annotated variables. The first one has been solved by proxying_GenericAlias.__call__but the second one remains unsolved. I plan to open a post undertypingfor them, if appropriate.