A special construct usable to annotate class objects.
For example, suppose we have the following classes:
class User: ... # Abstract base for User classes class BasicUser(User): ... class ProUser(User): ... class TeamUser(User): ...
And a function that takes a class argument that’s a subclass of User and returns an instance of the corresponding class:
U = TypeVar('U', bound=User) def new_user(user_class: Type[U]) -> U: user = user_class() # (Here we could write the user object to a database) return user joe = new_user(BasicUser)
At this point the type checker knows that joe has type BasicUser.