I am investigating the source code of a package, and noticed that classes are able to call certain methods that aren't defined within the class.
For example:
inst = ClassA()
meth = inst.meth1()
"some stuff printing to console"
However, meth1()
is not defined within ClassA
. In the ClassA definition, there is an input that references another class:
from package.sub.file import ClassB
class ClassA(ClassB):
...normal class stuff...
From another file:
class ClassB:
...normal class stuff...
def meth1(self):
...stuff...
My main question is how is this possible? How does meth1
become a method for ClassA
? I am confused as to why passing ClassB
as an input transfers all the methods associated with ClassB
to ClassA