Skip to content

Support as "PyAlias" in wrap_error  #14

@jselig-rigetti

Description

@jselig-rigetti

Since capitalization style between initialisms differs between python (prefer QCSError), and rust (prefer QcsError) it would be nice to have a similar pattern to py_wrap_type to make an alias:

use rigetti_pyo3::{py_wrap_error, wrap_error, create_init_submodule};
use pyo3::exceptions::{PyRuntimeError};

wrap_error!(
    ClientError(some_other_mod::ClientError) as "QCSClientError" // <-- feels most similar to other patterns
);

py_wrap_error!(
    this_mod,
    ClientError,
    QcsClientError, // <-- in its current state, the internal `pyo3::crate_exception!` annotates this with
                    // `#[allow(non_camel_case_types)]` so it is acceptable to use `QCSClientError` here
                    // without any changes.
    PyRuntimeError,
    // <-- the internal `pyo3::create_exception!` macro takes an optional `doc` parameter
    // that we aren't using, some potential re-use there. 
);

create_init_submodule! {
    errors: [QcsClientError], // <-- calls `std::stringify!(QcsClientError)` so would need to be changed
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions