Run-time behaviour of `TypeAliasType

It doesn’t work well with laziness because it’s unexpected that using isinstance() will result in e.g. a NameError from inside the evaluation of the type alias.

It doesn’t work well with type parameters because runtime isinstance() checks don’t work on parameterized generics. For example, if you write type MyList[T] = list[T], even if we had isinstance() delegate to the __value__ of the alias, it wouldn’t work:

>>> type MyList[T] = list[T]
>>> isinstance([], MyList.__value__)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: isinstance() argument 2 cannot be a parameterized generic

More generally, runtime isinstance() checks can’t see the value of type parameters. We aren’t going to go through the entire list to see whether something is a MyList[int].

1 Like