私はこれを持っています:
#! /usr/bin/env python
class myclass1(object):
def __new__(cls,arg):
print cls, arg, "in new"
ss = super(object,cls)
print ss, type(ss)
ss.__new__(cls,arg)
# super(object,cls).__new__(cls,arg)
# return object.__new__(cls,arg)
def __init__(self,arg):
self.arg = arg + 1
print self, self.arg, "in init"
if __name__ == '__main__':
m = myclass1(56)
エラーが発生します:
$ ./newtest.py
<class '__main__.myclass1'> 56 in new
<super: <class 'object'>, <myclass1 object>> <type 'super'>
Traceback (most recent call last):
File "./newtest.py", line 23, in <module>
m = myclass1(56)
File "./newtest.py", line 9, in __new__
ss.__new__(cls,arg)
TypeError: super.__new__(myclass1): myclass1 is not a subtype of super
エラーは有効です。わかりました。しかし、__new__のこのページでドキュメントが何を言っているのか、私は今混乱しています: http://docs.python.org/2.6/reference/datamodel.html#object.__new__
質問: 上記のドキュメントによると、私は何を間違っていますか? ドキュメントに対する私の理解のギャップはどこにありますか?