-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add #[name = "foo"] attribute to #[pymethods] #692
Conversation
CHANGELOG.md
Outdated
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. | |||
|
|||
## Unreleased | |||
|
|||
* Support for `#[name = "foo"]` attribute in `#[pymethods]`. [#692](https://github.com/PyO3/pyo3/pull/692) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bikeshed: maybe the attribute should be #[pyname]
instead of #[name]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[pyname]
could work, on the other hand, we already have #[text_signature]
and not #[pytext_signature]
, however #[name]
is much more likely to conflict with something in the future due to being a much more common word than #[text_signature]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the issues mentioned, it looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Thank you! |
I agree most users won't need this. There will be edge cases like the example originally supplied on #663. Note that the It's probably too breaking but I now actually think it would be nice to remove the required name argument from |
I've pushed changes to all the things you suggested.
Sorry. I'll do refactorings as separate PRs next time 😄 |
For alternatively, for consistency, just accept: #[getter]
#[name = "python_name"]
fn rust_name(&self) -> i32 {
0
}
#[getter(python_name2)]
fn rust_name2(&self) -> i32 {
0
} but not: #[getter(other_python_name)]
#[name = "python_name"]
fn rust_name(&self) -> i32 {
0
} |
I actually did have different error messages (not quite so detailed as that), but removed it on kngwyu's recommendation 😄
I did consider this too, but I felt that it's better to have just one way to set the python name for a getter / setter. If the consensus is to enable |
Thank you!
I often feel this kind of design decision difficult. |
Closes #663
To achieve this, I added to
FnSpec
:name
- the name of the Rust function this maps topython_name
- either the optionally-set#[name]
, or the.unraw()
rust nameWhile I was at it I did some refactoring to swap some
panic!
-s to spanned errors, and a bit of cleanup.TODO:
#[pyname]
perhaps?#[pyfunction]
?