Extend `#[pyo3(warn(message = "..."))]` to support enum variants too
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
Hi,
I'm looking for marking some enum variants as deprecated. A snippet of the code:
/// The public key algorithm used by an OpenPGP key.
#[pyclass(eq, skip_from_py_object)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum PublicKeyAlgorithm {
/// RSA (Encrypt or Sign)
RSAEncryptSign,
/// RSA Encrypt-Only, deprecated
#[deprecated]
RSAEncrypt,
}
Sadly currently this triggers deprecation warnings which cannot be silenced at the enum-variant level (only on module level, this is related to https://github.com/PyO3/pyo3/issues/4316 I think).
https://github.com/PyO3/pyo3/pull/4364 adds a better option for functions: #[pyo3(warn):
#[getter]
#[pyo3(warn(
message = "Prefer Sig.issuer_fingerprint",
category = pyo3::exceptions::PyDeprecationWarning
))]
pub fn issuer_fpr(&self) -> Option<String> {
self.issuer_fingerprint()
}
It doesn't seem to work on enum variants though, printing "error: expected name or constructor". I'm not sure if that's a technical limitation or just something not implemented yet but I think it'd be good idea to extend the pyo3 warn support to enum variants too.
Thanks for such a great library, it makes writing python bindings in Rust a true bliss! ❤️
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
Start by reproducing the reported "expected name or constructor" error with #[pyo3(warn(message = "..."))] on an enum variant, then compare it with the documented function usage and the linked pull request. Done means enum variants accept the warn option and produce the requested Python deprecation warning without requiring module-level suppression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100