6

重複の可能性:
Python 3の使用法super()

Python 3.2のドキュメントには、次のように書かれています。

2番目の引数を省略すると、返されるスーパーオブジェクトはバインドされません

私の理解では、unbound('unbound-to-instance'のように)オブジェクトはsuper(class、class)から返されるものです。では、super(class)の「unbound」とはどういう意味ですか?どのようにバインドしますか?

class Base:
    def printme(self): print("I'm base")

class Derived(Base):
    def printme(self): print("I'm derived")

class Derived2(Derived):
    def printme(self):
        super().printme()
# next-in-mro bound-to-self method

        super(Derived, self).printme()
# beyond-Derived-in-mro bound-to-self method

        super(Derived, Derived2).printme(self)
# beyond-Derived-in-mro-of-Derived2 unbound method

        super(Derived2).printme
# WTF is this? There's not even a printme attribute in it

Derived2().printme()
4

0 に答える 0