get_generic_alias

Get the generic alias for a type.

Given a type, its generic alias from typing module will be returned if it exists. For example:

typing.List
get_generic_alias(list)
get_generic_alias(dict)
# typing.Dict

This is mostly useful for python versions prior to 3.9, to get a version of a concrete type which supports __class_getitem__ . In 3.9+ types like list /dict /etc are subscriptable and can be used directly instead of their generic alias version.

Signature:

def get_generic_alias(type_: Type) -> Type:
...

Parameters:

  1. type_:

    Type
    Type