Any ideas about the best work around for __new__ losing its arguments?

后端 未结 3 993
没有蜡笔的小新
没有蜡笔的小新 2021-01-20 03:52

So, I only realised today that __new__ is deprecated for receiving arguments, as of python 2.6 (it isn\'t mentioned in the documentation, which is also not true

3条回答
  •  离开以前
    2021-01-20 04:41

    Thomas put me right in his answer, but I should add that the solution in my case was trivial: add a __new__ method to my base class with the lines:

    class Base(object):
        def __new__(cls, *args, **kws):
            instance = super(Base, cls).__new__(cls)
            instance.__init__(*args, **kws)
            return instance
    

提交回复
热议问题