PEP 747: TypeExpr: Type Hint for a Type Expression

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?

  1. Nested types

    is_assignable([1], list[int]) # True?
    
  2. 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 of orig_class availability 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 under typing for them, if appropriate.