super and __new__ confusion

前端 未结 1 693
陌清茗
陌清茗 2020-12-24 07:19

As what I just learned, I can use super() this way:
super(class, obj_of_class-or-_subclass_of_class)

Code goes below:



        
1条回答
  •  轮回少年
    2020-12-24 07:32

    From the Python release notes on overriding the __new__ method:

    __new__ is a static method, not a class method. I initially thought it would have to be a class method, and that's why I added the classmethod primitive. Unfortunately, with class methods, upcalls don't work right in this case, so I had to make it a static method with an explicit class as its first argument.

    Since __new__ is a static method, super(...).__new__ returns a static method. There is no binding of cls to the first argument in this case. All arguments need to be supplied explicitly.

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