Skip to content

Passing a TypeAlias as a type argument #8794

Answered by erictraut
a3ng7n asked this question in Q&A
Discussion options

You must be logged in to vote

For details about the type annotation Type[T], refer to this section of the Python typing spec. As indicated in the spec, a union type is not compatible with type[T]. Nor is a TypeAliasType value. That's because type[T] should be an instantiable class, and an attempt to call the a union type or TypeAliasType object will result in a runtime exception.

BTW, the uppercase version of Type and List are deprecated as of Python 3.9. You can now use type and list (the lowercase builtin symbols).

There is a new PEP under development that would introduce a way to support what you're doing here. However, I recommend against this approach. You're trying to use the runtime machinery of the static type…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@a3ng7n
Comment options

Answer selected by a3ng7n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants