当从基类继承时,实现__deepcopy__
并且继承类更改了中的参数__init__
,如何__deepcopy__
在继承类中重用来自基类的参数?
这里有一个例子:
class A(object):
def __init__(self, arg1, arg2):
self.arg1 = arg1
self.arg2 = arg2
def __deepcopy__(self, memo):
newone = type(self)(self.arg1, self.arg2)
...
class B(A):
def __init__(self, arg1):
A.__init__(self, arg1, None)
def __deepcopy__(self, memo):
newone = A.__deepcopy__(self, memo) # fails, because __deepcopy__ of
# A tries to create an instance of
# B with to many arguments
...