In the OP, distToPoint()
and isNear()
are both instance methods and as such, both take a reference to an instance (usually named self
) as its first argument. When an instance method called directly from the instance, the reference is passed implicitly, so
self.distToPoint(p)
works.
If you want to call an overridden parent method from the child class, then super()
could/should be used. In the following example, greet()
method is defined in both Parent
and Child
classes and if you want to call Parent
's greet()
, the prescribed way is via super()
, i.e. super().greet()
. It's also possible to do it via the class name, i.e. Parent.greet(self)
but there are many arguments against such hard-coding in favor of super()
such as flexibility, the ability to use method resolution order correctly etc.
class Parent:
def greet(self):
print("greetings from Parent!")
def parent_printer(self):
print("this is parent printer")
class Child(Parent):
def greet(self, parent=False):
if parent:
super().greet() # Parent's greet is called
else:
print("greetings from Child!")
def printer(self, greet=True):
if greet:
self.greet() # Child's greet is called
else:
self.parent_printer() # Parent's parent_printer is inherited
c = Child()
c.greet() # greetings from Child!
c.greet(parent=True) # greetings from Parent!
c.printer() # greetings from Child!
c.printer(greet=False) # this is parent printer