Fix function name shadowing
This commit is contained in:
parent
658bc6bb7c
commit
4966d93494
|
@ -0,0 +1 @@
|
||||||
|
Fix compile error for `#[pymethods]` and `#[pyfunction]` called "output".
|
|
@ -409,21 +409,22 @@ impl<'a> FnSpec<'a> {
|
||||||
let self_arg = self.tp.self_arg();
|
let self_arg = self.tp.self_arg();
|
||||||
let py = syn::Ident::new("_py", Span::call_site());
|
let py = syn::Ident::new("_py", Span::call_site());
|
||||||
let func_name = &self.name;
|
let func_name = &self.name;
|
||||||
let rust_name = if let Some(cls) = cls {
|
|
||||||
quote!(#cls::#func_name)
|
|
||||||
} else {
|
|
||||||
quote!(#func_name)
|
|
||||||
};
|
|
||||||
|
|
||||||
let rust_call = |args: Vec<TokenStream>| {
|
let rust_call = |args: Vec<TokenStream>| {
|
||||||
quote! {
|
quote! {
|
||||||
let mut ret = #rust_name(#self_arg #(#args),*);
|
let mut ret = function(#self_arg #(#args),*);
|
||||||
let owned = _pyo3::impl_::pymethods::OkWrap::wrap(ret, #py);
|
let owned = _pyo3::impl_::pymethods::OkWrap::wrap(ret, #py);
|
||||||
owned.map(|obj| _pyo3::conversion::IntoPyPointer::into_ptr(obj))
|
owned.map(|obj| _pyo3::conversion::IntoPyPointer::into_ptr(obj))
|
||||||
.map_err(::core::convert::Into::into)
|
.map_err(::core::convert::Into::into)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let rust_name = if let Some(cls) = cls {
|
||||||
|
quote!(#cls::#func_name)
|
||||||
|
} else {
|
||||||
|
quote!(#func_name)
|
||||||
|
};
|
||||||
|
|
||||||
Ok(match self.convention {
|
Ok(match self.convention {
|
||||||
CallingConvention::Noargs => {
|
CallingConvention::Noargs => {
|
||||||
let call = if !self.signature.arguments.is_empty() {
|
let call = if !self.signature.arguments.is_empty() {
|
||||||
|
@ -437,6 +438,7 @@ impl<'a> FnSpec<'a> {
|
||||||
#py: _pyo3::Python<'py>,
|
#py: _pyo3::Python<'py>,
|
||||||
_slf: *mut _pyo3::ffi::PyObject,
|
_slf: *mut _pyo3::ffi::PyObject,
|
||||||
) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> {
|
) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> {
|
||||||
|
let function = #rust_name; // Shadow the function name to avoid #3017
|
||||||
#deprecations
|
#deprecations
|
||||||
#self_conversion
|
#self_conversion
|
||||||
#call
|
#call
|
||||||
|
@ -454,6 +456,7 @@ impl<'a> FnSpec<'a> {
|
||||||
_nargs: _pyo3::ffi::Py_ssize_t,
|
_nargs: _pyo3::ffi::Py_ssize_t,
|
||||||
_kwnames: *mut _pyo3::ffi::PyObject
|
_kwnames: *mut _pyo3::ffi::PyObject
|
||||||
) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> {
|
) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> {
|
||||||
|
let function = #rust_name; // Shadow the function name to avoid #3017
|
||||||
#deprecations
|
#deprecations
|
||||||
#self_conversion
|
#self_conversion
|
||||||
#arg_convert
|
#arg_convert
|
||||||
|
@ -471,6 +474,7 @@ impl<'a> FnSpec<'a> {
|
||||||
_args: *mut _pyo3::ffi::PyObject,
|
_args: *mut _pyo3::ffi::PyObject,
|
||||||
_kwargs: *mut _pyo3::ffi::PyObject
|
_kwargs: *mut _pyo3::ffi::PyObject
|
||||||
) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> {
|
) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> {
|
||||||
|
let function = #rust_name; // Shadow the function name to avoid #3017
|
||||||
#deprecations
|
#deprecations
|
||||||
#self_conversion
|
#self_conversion
|
||||||
#arg_convert
|
#arg_convert
|
||||||
|
@ -489,6 +493,7 @@ impl<'a> FnSpec<'a> {
|
||||||
_kwargs: *mut _pyo3::ffi::PyObject
|
_kwargs: *mut _pyo3::ffi::PyObject
|
||||||
) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> {
|
) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> {
|
||||||
use _pyo3::callback::IntoPyCallbackOutput;
|
use _pyo3::callback::IntoPyCallbackOutput;
|
||||||
|
let function = #rust_name; // Shadow the function name to avoid #3017
|
||||||
#deprecations
|
#deprecations
|
||||||
#arg_convert
|
#arg_convert
|
||||||
let result = #call;
|
let result = #call;
|
||||||
|
|
|
@ -441,9 +441,9 @@ fn impl_py_class_attribute(cls: &syn::Type, spec: &FnSpec<'_>) -> syn::Result<Me
|
||||||
|
|
||||||
let name = &spec.name;
|
let name = &spec.name;
|
||||||
let fncall = if py_arg.is_some() {
|
let fncall = if py_arg.is_some() {
|
||||||
quote!(#cls::#name(py))
|
quote!(function(py))
|
||||||
} else {
|
} else {
|
||||||
quote!(#cls::#name())
|
quote!(function())
|
||||||
};
|
};
|
||||||
|
|
||||||
let wrapper_ident = format_ident!("__pymethod_{}__", name);
|
let wrapper_ident = format_ident!("__pymethod_{}__", name);
|
||||||
|
@ -452,6 +452,7 @@ fn impl_py_class_attribute(cls: &syn::Type, spec: &FnSpec<'_>) -> syn::Result<Me
|
||||||
|
|
||||||
let associated_method = quote! {
|
let associated_method = quote! {
|
||||||
fn #wrapper_ident(py: _pyo3::Python<'_>) -> _pyo3::PyResult<_pyo3::PyObject> {
|
fn #wrapper_ident(py: _pyo3::Python<'_>) -> _pyo3::PyResult<_pyo3::PyObject> {
|
||||||
|
let function = #cls::#name; // Shadow the method name to avoid #3017
|
||||||
#deprecations
|
#deprecations
|
||||||
let mut ret = #fncall;
|
let mut ret = #fncall;
|
||||||
let owned = _pyo3::impl_::pymethods::OkWrap::wrap(ret, py);
|
let owned = _pyo3::impl_::pymethods::OkWrap::wrap(ret, py);
|
||||||
|
@ -1151,12 +1152,14 @@ impl SlotDef {
|
||||||
*extract_error_mode,
|
*extract_error_mode,
|
||||||
return_mode.as_ref(),
|
return_mode.as_ref(),
|
||||||
)?;
|
)?;
|
||||||
|
let name = spec.name;
|
||||||
let associated_method = quote! {
|
let associated_method = quote! {
|
||||||
unsafe fn #wrapper_ident(
|
unsafe fn #wrapper_ident(
|
||||||
#py: _pyo3::Python<'_>,
|
#py: _pyo3::Python<'_>,
|
||||||
_raw_slf: *mut _pyo3::ffi::PyObject,
|
_raw_slf: *mut _pyo3::ffi::PyObject,
|
||||||
#(#arg_idents: #arg_types),*
|
#(#arg_idents: #arg_types),*
|
||||||
) -> _pyo3::PyResult<#ret_ty> {
|
) -> _pyo3::PyResult<#ret_ty> {
|
||||||
|
let function = #cls::#name; // Shadow the method name to avoid #3017
|
||||||
let _slf = _raw_slf;
|
let _slf = _raw_slf;
|
||||||
#body
|
#body
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue