0

How does one define copy and deepcopy methods for a Python type defined in a C extension?

Looking at the documentation, there doesn't appear to be a tp_ slot for these methods.

SU3
  • 5,064
  • 3
  • 35
  • 66

1 Answers1

2

There's no slot. You just define the same methods you'd define in Python, but in C. (Typically, that means implementing __reduce__ and getting the default __reduce__-based copy.copy and copy.deepcopy behavior, but you can also implement __copy__ and __deepcopy__ if you want.)

user2357112
  • 260,549
  • 28
  • 431
  • 505