PythonCall.jl icon indicating copy to clipboard operation
PythonCall.jl copied to clipboard

Support __copy__ and __deepcopy__?

Open cjdoris opened this issue 4 years ago • 3 comments

juliacall.AnyValue.__copy__ and __deepcopy__ could call Julia's copy and deepcopy.

Conversely, copy(::Py) and deepcopy_internal(::Py, ::IdDict) could call Python's copy.copy and copy.deepcopy.

https://docs.python.org/3/library/copy.html

cjdoris avatar Aug 23 '21 15:08 cjdoris

We can support memos by including the Julia memo dict at a special key in the Python memo dict, and vice versa.

cjdoris avatar Aug 23 '21 15:08 cjdoris

Note that you'll probably want to define Base.deepcopy_internal to at minimum increment the reference count, since otherwise calling deepcopy(::Py) in Julia will use the default implementation (that will just copy the pointer, which might lead to crashes since then the refcount will be wrong).

stevengj avatar May 02 '22 16:05 stevengj

See https://github.com/JuliaPy/PyCall.jl/pull/1039 for how PyCall.jl does it.

stevengj avatar Sep 23 '23 16:09 stevengj