PEP 695 type aliases not suitable as replacement for typing.TypeAlias?

From the Python documentation of typing.TypeAlias:

Deprecated since version 3.12: TypeAlias is deprecated in favor of the type statement, which creates instances of TypeAliasType and which natively supports forward references. Note that while TypeAlias and TypeAliasType serve similar purposes and have similar names, they are distinct and the latter is not the type of the former. Removal of TypeAlias is not currently planned, but users are encouraged to migrate to type statements.

Especially the final sentence is relevant here. I think it’s fair to call TypeAlias soft deprecated, since for most use-cases you should just use a type statement instead. So the deprecation in this case is about nudging people towards using the superior[1] construct for the intended use-case of TypeAlias, not necessarily about preventing people from using it at all.

For now you can keep using TypeAlias for those other use-cases if you like[2], with no imminent danger of your code breaking in the future. If your preference is to use TypeAlias this way, that’s fine, but I don’t think that should restrict the design of TypeAliasType.


  1. as in it supports forward references without having to wrap them in strings and it’s runtime introspectable ↩︎

  2. even if it can hide errors with forward references ↩︎

1 Like