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

Allow overriding generated python method names #663

Closed
programmerjake opened this issue Nov 12, 2019 · 0 comments · Fixed by #692
Closed

Allow overriding generated python method names #663

programmerjake opened this issue Nov 12, 2019 · 0 comments · Fixed by #692

Comments

@programmerjake
Copy link
Contributor

Allow code like:

#[pymethods]
impl MyType {
    // public API for Python
    #[name = "my_method"]
    #[args(arg2 = "None")]
    fn my_method_python(&self, arg1: i32, arg2: Option<i32>) {
        match arg2 {
            Some(arg2) => self.my_method_with_arg2(arg1, arg2),
            None => self.my_method(arg1),
        }
    }
}

impl MyType {
    // public API for Rust
    pub fn my_method(&self, arg1: i32) {
        unimplemented!()
    }
    pub fn my_method_with_arg2(&self, arg1: i32, arg2: i32) {
        unimplemented!()
    }
}

my_method is accessible from Python:

a = MyType()
a.my_method(1)
a.my_method(1, 2)

This is useful to allow the Rust and Python APIs for a type to differ somewhat due to different conventions between Python and Rust.

There is already precedent for this kind of renaming: #[pyclass(name = MyType)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants