If I was trying to define a function that can take any object whose class type inherited from a specific base class, how can I define that using the typing module in python.
I have seen the example shown here: In python type-hinting, how can I make an argument accept any subclass of a base class?, but the answer accepted is specific. I would like a general one.
For example
import typing
class A:
def __init__(self):
pass
class B(A):
def __init__(self):
super(B, self).__init__()
class C:
# typing.InstanceBase was used as an example method
def __init__(self, object: typing.InstanceBase[A]):
self.object = object
a = A()
b = B()
>> c1 = C(a) # Would not complain about typing
>> c2 = C(b) # Would not complain about typing