Fix usage of raw idents with #[pyo3(set)]
This commit is contained in:
parent
11084e1433
commit
a8ec946fc3
|
@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
|
||||
* Clear error indicator when the exception is handled on the Rust side. [#719](https://github.com/PyO3/pyo3/pull/719)
|
||||
* Fixed unsoundness of subclassing. [#683](https://github.com/PyO3/pyo3/pull/683).
|
||||
* Usage of raw identifiers with `#[pyo3(set)]`. [#745](https://github.com/PyO3/pyo3/pull/745)
|
||||
|
||||
### Removed
|
||||
|
||||
|
|
|
@ -427,7 +427,7 @@ fn impl_descriptors(
|
|||
.flat_map(|&(ref field, ref fns)| {
|
||||
fns.iter()
|
||||
.map(|desc| {
|
||||
let name = field.ident.clone().unwrap();
|
||||
let name = field.ident.as_ref().unwrap();
|
||||
let field_ty = &field.ty;
|
||||
match *desc {
|
||||
FnType::Getter => {
|
||||
|
@ -441,7 +441,7 @@ fn impl_descriptors(
|
|||
}
|
||||
FnType::Setter => {
|
||||
let setter_name =
|
||||
syn::Ident::new(&format!("set_{}", name), Span::call_site());
|
||||
syn::Ident::new(&format!("set_{}", name.unraw()), Span::call_site());
|
||||
quote! {
|
||||
impl #cls {
|
||||
fn #setter_name(&mut self, value: #field_ty) -> pyo3::PyResult<()> {
|
||||
|
@ -463,7 +463,7 @@ fn impl_descriptors(
|
|||
.flat_map(|&(ref field, ref fns)| {
|
||||
fns.iter()
|
||||
.map(|desc| {
|
||||
let name = field.ident.clone().unwrap();
|
||||
let name = field.ident.as_ref().unwrap();
|
||||
|
||||
// FIXME better doc?
|
||||
let doc = syn::LitStr::new(&name.to_string(), name.span());
|
||||
|
@ -483,8 +483,10 @@ fn impl_descriptors(
|
|||
Ok(impl_py_getter_def(&spec, &impl_wrap_getter(&cls, &spec)?))
|
||||
}
|
||||
FnType::Setter => {
|
||||
let setter_name =
|
||||
syn::Ident::new(&format!("set_{}", name), Span::call_site());
|
||||
let setter_name = syn::Ident::new(
|
||||
&format!("set_{}", name.unraw()),
|
||||
Span::call_site(),
|
||||
);
|
||||
let spec = FnSpec {
|
||||
tp: FnType::Setter,
|
||||
name: &setter_name,
|
||||
|
|
|
@ -69,7 +69,10 @@ fn custom_names() {
|
|||
}
|
||||
|
||||
#[pyclass]
|
||||
struct RawIdents {}
|
||||
struct RawIdents {
|
||||
#[pyo3(get, set)]
|
||||
r#type: i64,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl RawIdents {
|
||||
|
@ -83,6 +86,7 @@ fn test_raw_idents() {
|
|||
let typeobj = py.get_type::<RawIdents>();
|
||||
py_assert!(py, typeobj, "not hasattr(typeobj, 'r#fn')");
|
||||
py_assert!(py, typeobj, "hasattr(typeobj, 'fn')");
|
||||
py_assert!(py, typeobj, "hasattr(typeobj, 'type')");
|
||||
}
|
||||
|
||||
#[pyclass]
|
||||
|
|
Loading…
Reference in New Issue