Problem using copy.copy with my own class

Jeffrey Barish jeff_barish at earthlink.net
Wed Apr 23 21:48:05 EDT 2008


Marc 'BlackJack' Rintsch wrote:
> Please simplify the code to a minimal example that still has the problem
> and *show it to us*.  It's hard to spot errors in code that nobody except
> you knows.

Here it is:

import copy

class Test(int):
    def __new__(cls, arg1, arg2):
        return int.__new__(cls, arg1)

    def __init__(self, arg1, arg2):
        self.arg2 = arg2

if __name__ == '__main__':
    t = Test(0, 0)
    t_copy = copy.copy(t)

Traceback (most recent call last):
  File "copytest.py", line 12, in <module>
    t_copy = copy.copy(t)
  File "/usr/lib/python2.5/copy.py", line 95, in copy
    return _reconstruct(x, rv, 0)
  File "/usr/lib/python2.5/copy.py", line 322, in _reconstruct
    y = callable(*args)
  File "/usr/lib/python2.5/copy_reg.py", line 92, in __newobj__
    return cls.__new__(cls, *args)
TypeError: __new__() takes exactly 3 arguments (2 given)
-- 
Jeffrey Barish




More information about the Python-list mailing list