Skip to content

Chaining parametrization on generic class #8867

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

You must be logged in to vote

The statement Sub = Model[T] is the old-style (PEP 484) way to define a generic type alias. It's equivalent to the less-old-style Sub: TypeAlias = Model[T] or the modern type Sub[T] = Model[T].

Once a generic type alias is defined, you can specialize it using subscripts.

In your first code snippet, you're not defining a type alias, and Model[T][int] has no valid meaning to a type checker. For the same reason, A[int, list[S]][str] is invalid.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Viicos
Comment options

@Viicos
Comment options

@erictraut
Comment options

Answer selected by Viicos
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