How to do this Class inheritance in Python?
<p>I have a Python/<a href="https://github.com/tornadoweb/tornado" rel="nofollow">Tornado</a> application that responds to HTTP requests with the following 3 classes:</p>

<pre><code>import tornado.web
class MyClass1(tornado.web.RequestHandler):
    x = 1
    y = 2

    def my_method1(self):
        print "Hello World"


class MyClass2(MyClass1):

    @tornado.web.authenticated
    def get(self):
        #Do Something 1
        pass

    @tornado.web.authenticated
    def post(self):
        #Do Something 2
        pass


class MyClass3(MyClass2):
    pass
</code></pre>

<p>I would like all instances <code>MyClass2</code> to have an instance variable <code>m</code> set to the integer 3. But any instances of <code>MyClass3</code> should over-ride that and have <code>m</code> set to the integer 4. How can I do it?</p>

<p>I tried adding the following constructors to <code>MyClass2</code> and <code>MyClass3</code> respectively, but then when I try to create an instance of <code>MyClass3</code>, I get the following error: <code>TypeError: __init__() takes exactly 1 argument (3 given)</code></p>

<p>MyClass2.<strong>init</strong>():</p>

<pre><code>def __init__(self):
    self.m = 3 # This value will be overridden by a subclass
</code></pre>

<p>MyClass3.<strong>init</strong>():</p>

<pre><code>def __init__(self):
    self.m = 4
</code></pre>

<p><code>ReequestHandler</code>'s <a href="http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler" rel="nofollow">constructor takes arguments</a>:</p>

<pre><code>class RequestHandler(object):
    ...
    def __init__(self, application, request, **kwargs):
        ...
</code></pre>

<p>When you inherit <code>RequestHandler</code> you then either:</p>

<p>a) Do not override <code>__init__</code> (i.e. do not provide your own constructor)
or
b) If you override <code>__init__</code> (provide your own constructor), then your constructor should have the same signature, since the framework will call the constructor.</p>

python inheritance tornado