What is a wrapper_descriptor, and why is Foo.__init__() one in this case?

前端 未结 1 483
独厮守ぢ
独厮守ぢ 2020-12-11 15:47
import inspect

class Foo(object):
    pass

if __name__ == \'__main__\':
    print type(Foo.__init__)
    print inspect.getsourcelines(Foo.__init__)
相关标签:
1条回答
  • 2020-12-11 16:01

    What you've run into is an implementation detail. This is pretty typical for classes implemented in C, as object is. It's not a Python method, it is a C method, and the wrapper is part of this interface.

    Why is there an __init__ in the class dict at all?

    It's not in the class dict, it's in the object dict. object has an __init__ so that when you try to call your class's base classes' __init__ methods using super(), it doesn't fail.

    0 讨论(0)
提交回复
热议问题