Let's say I have the following....
class BaseHandler:
def foo(self):
print "Hello"
class HomeHandler(BaseHandler):
pass
Then I do the following...
test = HomeHandler()
test.foo()
How can HomeHandler call foo() when I never created an instance of
BaseHandler?
When you ask for an attribute of an instance of a class, the attribute
lookup first looks at the instance; if not there, then the class; if not
there, then superclass(es); and so on back to class 'object'.
<method-wrapper '__hash__' of C object at 0x00FCB5D0>
# how does this happen when C has no __hash__ method?
<slot wrapper '__hash__' of 'object' objects>
# C inherits __hash__ and other special methods from 'object'
1035101
# uses the default, inherited method.
Most syntactic operations and builtins are ultimately converted to a
special method call, often inherited like this. In fact, c.x is
converted to object.__getattribute__(c, 'x').
<method-wrapper '__hash__' of C object at 0x00FCB5D0>
You do need to understand inheritance. On the other hand, do not worry
about behind-the-scenes implementation details like 'method_wrapper' and
'slot_wrapper' classes, which may be CPython specific.