Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/spec/generics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,17 @@ the runtime class of the objects created by instantiating them doesn't
record the distinction. This behavior is called "type erasure"; it is
common practice in languages with generics (e.g. Java, TypeScript).

Additionally, objects like ``Node[int]`` will not be considered as a class at the runtime,
even though they behave like them (e.g they can be instantiated). This is because these objects are instances of ``GenericAlias``::

import inspect

inspect.isclass(Node) # True
inspect.isclass(Node[int]) # False
inspect.isclass(Node[str]) # False

type(Node[int]) # <class 'typing._GenericAlias'>

Using generic classes (parameterized or not) to access attributes will result
in type check failure. Outside the class definition body, a class attribute
cannot be assigned, and can only be looked up by accessing it through a
Expand Down