Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trait for cloning while the GIL is held #4133

Open
adamreichold opened this issue Apr 28, 2024 · 1 comment
Open

Add trait for cloning while the GIL is held #4133

adamreichold opened this issue Apr 28, 2024 · 1 comment

Comments

@adamreichold
Copy link
Member

Due to issues making delay reference count increments sound, they were removed #4095 and replaced by an Clone implementation for Py which will panic without the GIL being held, gated by the py-clone feature.

This has several usability downsides, e.g. #[pyo3(get)] stops working with Py<T> fields which however is a very important use case when sharing data with Python code. Similarly, the PyBacked* types cannot be unconditionally Clone themselves.

Both problems (and likely others) should be resolvable if we add a trait, e.g. CloneRef or PyClone with signature

fn clone_ref(&self, py: Python<'_>) -> Self;

and implement it unconditionally for Py<T> and add a blanket impl based on Clone. The proc macro machinery behind #[pyo3(get)] could then go via this trait instead of the plain Clone.

@davidhewitt
Copy link
Member

👍 I guess we probably want a derive macro for this trait too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants