JuliaPy / PythonCall.jl

Python and Julia in harmony.
https://juliapy.github.io/PythonCall.jl/stable/
MIT License
807 stars 64 forks source link

Support __copy__ and __deepcopy__? #35

Open cjdoris opened 3 years ago

cjdoris commented 3 years ago

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 commented 3 years ago

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

stevengj commented 2 years ago

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 commented 1 year ago

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