简而言之,从python开始,
Where C is a class, the statement
x=C(23)
is equivalent to:x = C.__new__(C, 23) if isinstance(x, C): type(x).__init__(x, 23)
From my understanding object.__new__
creates a new, uninitialized instance of the class it receives as its first argument.
Why is there need to be a check with the isinstance()
. Isn't it obvious that __new__
will return a object of type C
.
如果此测试失败,会发生什么情况?
Since classes
are callables
, is the call to __new__
is done in the class's __call()__
method
我在这里想念什么吗,请向我澄清一下