A.__dict__['new'] is a staticmethod handle, where as A.__new__ is the actual base function.
https://docs.python.org/2/howto/descriptor.html#static-methods-and-class-methods
if you need to call a function or get it using a string (at runtime), use getattr(A, '__new__')
>>> A.__new__ <function A.__new__ at 0x02E69618> >>> getattr(A, '__new__') <function A.__new__ at 0x02E69618>
Python 3.5.1
class A(object): def __new__(cls, a): print(a) return object.__new__(cls) def f(a): print(a) >>> A.__dict__['__new__'] <staticmethod object at 0x02E66B70> >>> A.__new__ <function A.__new__ at 0x02E69618> >>> object.__new__ <built-in method __new__ of type object at 0x64EC98E8> >>> A.__new__(A, 'hello') hello <__main__.A object at 0x02E73BF0> >>> A.__dict__['__new__'](A, 'hello') Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> TypeError: 'staticmethod' object is not callable >>> getattr(A, '__new__') <function A.__new__ at 0x02E69618>
source share