I have some classes that look like this.
class Parent:
def f(self, x):
# Is this bad practice?
return x * self.number
class Child(Parent):
def __init__(self, number):
# We create number in Child.
self.number = number
child = Child(2)
child.f(3) # 6 - this runs
It seems to be going against 'explicit is better than implicit' to define self.number in Parent without any indication that you must override it in Child. But it does run.
What's the best way to handle this? I could define it in Parent's __init__ but the user will only need to refer to Child and I don't want to duplicate the params passed to Parent and Child.