Skip to content
Discussion options

You must be logged in to vote

If you provide an explicit specialization for a generic class (e.g. Bar[T] or Bar[Any]), then the type checker will honor that specialization. If you don't provide an explicit specialization, then the type checker will assume the default value for the argument. If no such default is specified, the default becomes Any.

The fact that Bar[T] or Bar[Any] is represented as a GenericAlias at runtime is an implementation detail of the type system in Python. For all intents and purposes it acts like the original class object. For example, reveal_type(list[int]) will reveal type[list[int]. It's not GenericAlias. You won't see GenericAlias appear anywhere within the Python typing spec.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@BaconPancakes
Comment options

@erictraut
Comment options

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