I would like to use an inherited variable as one of the default argument to a derived class's method. I want to do something that looks like the following :
class BaseFoo:
_inherited = 'someval'
class Foo(BaseFoo):
def dosomething( bar = _inherited ):
print( bar ) # should print someval if we call dosomething()
I have tried using super()._inherited. But since super() needs an instance, putting it as a default arg will raise a RunTimeError: super() no arguments
I have also tried using self._inherited. But it returns a NameError, self not defined. I know that I can access _inherited within a function with either self or super(). But how do I do it on the while defining some default args ?
Edit : I am aware on how to access inherited attributes in subclasses. But This question focuses on using them as default arguments. For those looking on accessing the attributes may refer to Accessing attribute from parent class inside child class