`&mut self` reference in `__setstate__` signature is incompatible with frozen pyclasses
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
It'd be really nice if you could somehow return a new instance from __setstate__ instead of mutating an instance that is handed to you in the signature.
Right now that's not possible. See #4465 for more related discussion.
Consider the PyDecoder class in tokenizers:
I can't easily make this class frozen because it has a __setstate__ implementation that takes &mut self. The only way to avoid that is to use interior mutability (e.g. with a Mutex) but I'm having trouble with that because PyDecoderWrapper contains an Arc<RwLock>. It occurs to me that I wouldn't need mutability at all for this class, except to make the class pickleable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the discussion in #4465 and inspect the linked tokenizers bindings/python/src/decoders.rs entry at the PyDecoder setstate implementation, including PyDecoderWrapper. Trace the current PyO3 signature and frozen-class constraints; done means the supported deserialization behavior is defined and covered for classes that cannot mutate their instance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100