开发者

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 PyD开发者_如何学Cev 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?


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.


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


The "former" AuthProxy is created by __generate_proxies (it's not very nice code, there is even an exec and eval in it :)), but the author wanted also define some methods on top of it.


To make Eclipse stop whining about it, do this:

class AuthProxy(AuthProxy): #@UndefinedVariable

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜