I have a set of sub-classes that should all define an attribute x
that should either evaluate to True or False. In order to catch bugs when I forget to set this value in a subclass, I would like to set it in its superclass to a value for which truth evaluation results in an error. Is there any built-in value in Python with this behaviour? I sort of expected NotImplemented
to have this behaviour, but it evaluates to True
.
I could set it to numpy.array([0, 0])
where if x:
raises ValueError
, but that feels wrong. Likewise, I could define my own class where __bool__
raises an exception. But is there any built-in value appropriate for this purpose?
Other alternatives would be to set a property (abstract or not) or to not define it at all (so we get AttributeError
).