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 specifying __name__ and __doc__ in PyCFunction::new_closure #2665

Closed
dalcde opened this issue Oct 8, 2022 · 1 comment
Closed

Support specifying __name__ and __doc__ in PyCFunction::new_closure #2665

dalcde opened this issue Oct 8, 2022 · 1 comment

Comments

@dalcde
Copy link
Contributor

dalcde commented Oct 8, 2022

This seems fairly easy to support if we only accept &'static str as the
arguments. These arguments are mostly useful only when the function lives
forever, so users who have an owned string can simply leak it to get a
&'static str.

I'm not sure what the correct API change would be. Having e.g.
PyCFunction::new_closure_with_name_and_doc would be backwards compatible but
the duplication of APIs could be annoying in the long run.

@davidhewitt
Copy link
Member

Sure thing, we already did similar to PyErr::new_type in #2027.

A PR to change PyCFunction::new_closure to have additional extra arguments as a breaking change in 0.18 would be ok in my opinion.

dalcde added a commit to dalcde/pyo3 that referenced this issue Oct 15, 2022
These arguments accept either a &'static str or an owned string (or more
generally, anything implementing Into<Cow<'static, str>>.
PyCFunction::new and PyCFunction::new_with_keywords are also modified to
support owned strings.

The main breaking change outside of impl_ is the modified function
signature of new_closure. The new and new_with_keywords function now
take more general arguments, which is backwards compatible but might
break type inference in rare cases.

Fixes PyO3#2665
dalcde added a commit to dalcde/pyo3 that referenced this issue Oct 15, 2022
These arguments accept either a &'static str or an owned string (or more
generally, anything implementing Into<Cow<'static, str>>.
PyCFunction::new and PyCFunction::new_with_keywords are also modified to
support owned strings.

The main breaking change outside of impl_ is the modified function
signature of new_closure. The new and new_with_keywords function now
take more general arguments, which is backwards compatible but might
break type inference in rare cases.

Fixes PyO3#2665
@mejrs mejrs closed this as completed in 9201a7d Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants