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

Pickle support for PyErr #4728

Open
TennyZhuang opened this issue Nov 25, 2024 · 1 comment
Open

Pickle support for PyErr #4728

TennyZhuang opened this issue Nov 25, 2024 · 1 comment

Comments

@TennyZhuang
Copy link

Pickle support was already discussed in #100, customizing __setstate__, __getstate__ and __getnewargs_ex__ works well for customized pyclass.

Unfortunately, when we want to create customized exception using create_exception, it's hard to implement such methods. It seems that the arguments are stored in PyErr instead of the class itself, how can we implement these magic methods ourselves?

#[pyclass(extends=PyException, subclass)]
pub struct Error;

Of course, it's better for pyo3 to support these methods directly on PyErr. I'd like to help if there is a consensus to do that.

@Icxolu
Copy link
Contributor

Icxolu commented Nov 25, 2024

I would say the goal is to make exceptions work exactly like your snippet. Create a custom pyclass and inherit from an exception type. That way it's easy to add custom fields, methods and protocols. I think the missing pieces are an easier way to convert these classes into a PyErr, so that they can be raised to Python and a way to make that work on abi3 (potentially #4678 can help with that)

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