I am trying to understand a certain OAuth2/web2py integration, but some quirks in the python class model are making it difficult for me to grasp. Specifically, I have this web2py controller:
def google():
if 'state' in request.vars and request.vars.state == 'google':
session.state = request.vars.state
person = Person("google")
print person.render()
return person.render()
So we have are using the Person class here. The implementation is like this:
class Person(Base):
No __init__ is present in the Person class. The Base class has an __init__ function:
class Base(object):
def __init__(
self,
hooks=[],
theme="%(name)s/",
view="app/generic",
meta=None,
context=None
):
from gluon.storage import Storage
self.meta = meta or Storage()
self.context = context or Storage()
self.context.alerts = []
self.context.content_types = []
self.context.categories = []
self.context.menus = []
self.context.internalpages = []
self.theme = theme
self.view = view
# hooks call
self.start()
self.build()
self.pre_render()
# aditional hooks
if not isinstance(hooks, list):
hooks = [hooks]
for hook in hooks:
self.__getattribute__(hook)()
So my questions is as follows: If Person is not explicitly calling Base.__init__, will it be called at all?
Or, to make it more general: will the base class __init__ function be called if the derived class has no __init__ function? And if the derived class has an __init__ function but does not explicitly call the base class __init__ function?
If the derived class has no
__init__function, the parent’s class__init__will be inherited and called.If the derived class has an
__init__function which does not call the parent’s__init__, the parent’s__init__will not be called.