[Python-ideas] Adding a `object.__deepcopy__`

1 view
Skip to first unread message

Ram Rachum

unread,
Dec 20, 2009, 8:54:39 AM12/20/09
to python...@python.org
Do you think there should be a `__deepcopy__` method for `object`? This will
solve a little problem I have here:

http://stackoverflow.com/questions/1933621/deepcopy-a-simple-python-object

I also think it's a more elegant solution than the way it works now.


Ram.

_______________________________________________
Python-ideas mailing list
Python...@python.org
http://mail.python.org/mailman/listinfo/python-ideas

Marcin 'Qrczak' Kowalczyk

unread,
Dec 20, 2009, 9:04:25 AM12/20/09
to Ram Rachum, python...@python.org
2009/12/20 Ram Rachum <coo...@cool-rr.com>:

> Do you think there should be a `__deepcopy__` method for `object`?

No. Deep copy is an ill-defined concept. There is no universal notion
of a deep copy, various applications need different amount of copying.
Also, various applications need different amount of sharing and cycle
detection while copying. There is no universal solution which fits
all.

Use a domain-specific function instead.

--
Marcin Kowalczyk

Terry Reedy

unread,
Dec 20, 2009, 3:19:00 PM12/20/09
to python...@python.org
On 12/20/2009 8:54 AM, Ram Rachum wrote:
> Do you think there should be a `__deepcopy__` method for `object`? This will
> solve a little problem I have here:
>
> http://stackoverflow.com/questions/1933621/deepcopy-a-simple-python-object
>
> I also think it's a more elegant solution than the way it works now.

To me, the concept 'deepcopy' only applies to collections, and object
instances are not collections, hence object.__deepcopy__ would be
non-sensical.

Terry Jan Reedy

Reply all
Reply to author
Forward
0 new messages