When you specify cls: A, you're saying that cls expects an instance of type A. The type hint to specify cls as a class object for the type A (or its subtypes) uses typing.Type.
from typing import Type
def process_any_subclass_type_of_A(cls: Type[A]):
pass
From The type of class objects :
Sometimes you want to talk about class objects that inherit from a given class. This can be spelled as
Type[C]whereCis a class. In other words, whenCis the name of a class, usingCto annotate an argument declares that the argument is an instance ofC(or of a subclass ofC), but usingType[C]as an argument annotation declares that the argument is a class object deriving fromC(orCitself).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With