Making a class method recognize which class context it's running in
<p>I need to refactor existing code by collapsing a method that's copy-and-pasted between various classed that inherit from one another into a single method. 
So I produced the following code:</p>

<pre><code>class A(object):
    def rec(self):
        return 1

class B(A):
    def rec(self):
        return self.rec_gen(B)

    def rec_gen(self, rec_class):
        return super(rec_class, self).rec() + 1

class C(B):
    def rec(self):
        return self.rec_gen(C)

if __name__=='__main__':
    b = B(); c = C()
    print c.rec()
    print b.rec()
</code></pre>

<p>And the output:</p>

<pre><code>3
2
</code></pre>

<p>What still bothers me is that in the 'rec' method I need to tell 'rec_gen' the context of the class in which it's running. Is there a way for 'rec_gen' to figure it out by itself in runtime?</p>
