考虑以下情况:
class Meta(type):
def shadowed(cls):
print "Meta.shadowed()"
def unshadowed(cls):
print "Meta.unshadowed()"
class Foo(object):
__metaclass__ = Meta
def shadowed(self):
print "Foo.shadowed()"
我可以调用获取绑定方法unshadowed
,Foo
它工作正常:
>>> Foo.unshadowed
<bound method Meta.unshadowed of <class '__main__.Foo'>>
>>> Foo.unshadowed()
Meta.unshadowed()
但是,我似乎无法打开绑定方法shadowed
-Foo
它将我引导到必须使用以下实例调用的未绑定方法Foo
:
>>> Foo.shadowed
<unbound method Foo.shadowed>
>>> Foo.shadowed()
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
Foo.shadowed()
TypeError: unbound method shadowed() must be called with Foo instance as first argument (got nothing instead)
有什么办法得到<bound method Meta.shadowed of <class '__main__.Foo'>>
吗?