I've a class structure like
class Parent:
value_type = (object,)
def __init__(self, value):
if not isinstance(value, value_type):
raise ValueError
self.value = value
class Derived(Parent):
value_type = (str,)
When I create an instance variable of derived class as
d = Derived(555)
It doesn't raises any error. (The behaviour I need is that it should raise an error in this case as 555 is not a str)
Is there any way to make the parent class constructor use the derived class attribute value_type instead of it's own class attribute?
I know passing value_type as a parameter to __init__ function is a solution, but the value_type should be same throughout the class, so I don't want to redundantly add same value_type field everytime to initialize a derived class instance.
NameError: name 'value_type' is not defined.TypeError, and ideally with more information.