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

pyfn: deprecate name argument #1610

Merged
merged 1 commit into from
May 23, 2021
Merged

pyfn: deprecate name argument #1610

merged 1 commit into from
May 23, 2021

Conversation

davidhewitt
Copy link
Member

This PR makes the second "name" argument to #[pyfn] both optional and deprecated in favour of #[pyo3(name = "...")]. This is part of #1601

This has the nice effect that now #[pyfunction] and #[pyfn(m)] take equivalent options, so I have rewritten the documentation to primarily talk about #[pyfunction], and #[pyfn] is introduced as syntax sugar.

Before:

#[pymodule]
fn rust2py(py: Python, m: &PyModule) -> PyResult<()> {

    #[pyfn(m, "sum_as_string")]
    fn sum_as_string() { }

    #[pyfn(m, "custom_name")
    fn foobar_to_rename() { }

    Ok(())
}

After:

#[pymodule]
fn rust2py(py: Python, m: &PyModule) -> PyResult<()> {

    #[pyfn(m)]
    fn sum_as_string() { }

    #[pyfn(m)]
    #[pyo3(name = "custom_name"]
    fn foobar_to_rename() { }

    Ok(())
}

@davidhewitt
Copy link
Member Author

If anyone's got any opinions on this, or wants to review the code, please let me know before the end of the weekend. Else I'll assume this is all fine and merge it before continuing with the rest of the items in #1601

@davidhewitt
Copy link
Member Author

Merging as promised! If there is any feedback on this I can always make follow-up PRs (or revert).

@davidhewitt davidhewitt merged commit cfdd535 into PyO3:main May 23, 2021
@davidhewitt davidhewitt deleted the pyfn-name branch May 23, 2021 22:08
@davidhewitt davidhewitt mentioned this pull request Jun 4, 2021
7 tasks
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

Successfully merging this pull request may close these issues.

1 participant