I need to declare an abstract instance variable in an abstract base class. After looking at Python: abstract instance variable?, it seems the one way to do that is with type annotations, e.g.,,
class base(ABC):
var : str
If var
here can take on multiple types, e.g., str
or int
, how would that work?
I tried
class base(ABC):
var : str | int
but that gives the error
val : int | str
TypeError: unsupported operand type(s) for |: 'type' and 'type'
Also, I'm not tied to annotations, so if there's a better way to accomplish what I need, I'm definitely open to switching.