SU3
SU3

Reputation: 5387

copy and deepcopy in Python C API

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.

Upvotes: 1

Views: 250

Answers (1)

user2357112
user2357112

Reputation: 280993

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.)

Upvotes: 3

Related Questions