Skip to content

Extend #[pyo3(warn(message = "..."))] to support enum variants too #5888

@wiktor-k

Description

@wiktor-k

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 #4316 I think).

#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! ❤️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions