Python 3 type annotations and subclasses

Inheritance also applies to annotated types. Any instance of Foo which is a subtype of FooBase is also a valid object of the type FooBase. So you can pass a FooBase object but also a Foo object to the function.

If you want to limit the function to only subclasses of FooBar, you could take a look at the Type[C] construct: The type of class objects.

Leave a Comment

tech