0

I have a library (pymunk) Im maintaining. Should I add my own copy() method on all the relevant classes or let the users of the library use the standard library copy.deepcopy method when they want a copy?

Recently a user asked about a method to copy a world object. At that time the library did not support any way to do this. However, now I have added support for pickle, so as a consequence copy.deepcopy automatically works.

The question is if its best to have a copy method on the objects provided by the library or just defer to the copy.deepcopy in the standard library. Some other libraries provides their own copy method, such as numpy array copy and pandas dataframe copy.

Adding a extra copy method is not very complicated since I can just call deepcopy, like this:

import copy

class A():
  def copy(self):
    return copy.deepcopy(self)

My concern is about clarity and ease of use. (the python zen "There should be one—and preferably only one—obvious way to do it.")

viblo
  • 4,159
  • 4
  • 20
  • 28

0 Answers0