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

Support as "PyAlias" in wrap_error #14

Open
jselig-rigetti opened this issue Feb 22, 2023 · 0 comments
Open

Support as "PyAlias" in wrap_error #14

jselig-rigetti opened this issue Feb 22, 2023 · 0 comments

Comments

@jselig-rigetti
Copy link
Collaborator

jselig-rigetti commented Feb 22, 2023

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant