Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python class that inherits from itself? How does this work?

Relatively new to Python, and I saw the following construct in the PyFacebook library (source here: http://github.com/sciyoshi/pyfacebook/blob/master/facebook/init.py#L660). I'm curious what this does because it appears to be a class that inherits from itself.

class AuthProxy(AuthProxy):
    """Special proxy for facebook.auth."""

    def getSession(self):
        """Facebook API call. See http://developers.facebook.com/documentation.php?v=1.0&method=auth.getSession"""
        ...
        return result

    def createToken(self):
        """Facebook API call. See http://developers.facebook.com/documentation.php?v=1.0&method=auth.createToken"""
        ...
        return token

what is this doing?

Tangentially related, I'm using PyDev in Eclipse and it's flagging this as an error. I'm guessing that's not the case. Anyway to let Eclipse know this is good?

like image 726
Bialecki Avatar asked Jan 16 '10 19:01

Bialecki


2 Answers

The class statement there doesn't make the class inherit from itself, it creates a class object with the current value of AuthProxy as a superclass, and then assigns the class object to the variable 'AuthProxy', presumably overwriting the previously assigned AuthProxy that it inherited from.

Essentially, it's about the same as x = f(x): x isn't the value of f on itself, there's no circular dependence-- there's just the old x, and the new x. The old AuthProxy, and the new AuthProxy.

like image 141
Devin Jeanpierre Avatar answered Oct 29 '22 15:10

Devin Jeanpierre


It's using the AuthProxy imported from a different module (check your imports) and deriving from it.

like image 40
Ignacio Vazquez-Abrams Avatar answered Oct 29 '22 15:10

Ignacio Vazquez-Abrams