diff --git a/newsfragments/3022.fixed.md b/newsfragments/3022.fixed.md new file mode 100644 index 00000000000..fe89640b64a --- /dev/null +++ b/newsfragments/3022.fixed.md @@ -0,0 +1 @@ +Fix compile error for `#[pymethods]` and `#[pyfunction]` called "output". diff --git a/pyo3-macros-backend/src/method.rs b/pyo3-macros-backend/src/method.rs index 9b40ac007e2..85dddf2e42e 100644 --- a/pyo3-macros-backend/src/method.rs +++ b/pyo3-macros-backend/src/method.rs @@ -409,21 +409,22 @@ impl<'a> FnSpec<'a> { let self_arg = self.tp.self_arg(); let py = syn::Ident::new("_py", Span::call_site()); 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| { 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); owned.map(|obj| _pyo3::conversion::IntoPyPointer::into_ptr(obj)) .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 { CallingConvention::Noargs => { let call = if !self.signature.arguments.is_empty() { @@ -437,6 +438,7 @@ impl<'a> FnSpec<'a> { #py: _pyo3::Python<'py>, _slf: *mut _pyo3::ffi::PyObject, ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = #rust_name; // Shadow the function name to avoid #3017 #deprecations #self_conversion #call @@ -454,6 +456,7 @@ impl<'a> FnSpec<'a> { _nargs: _pyo3::ffi::Py_ssize_t, _kwnames: *mut _pyo3::ffi::PyObject ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = #rust_name; // Shadow the function name to avoid #3017 #deprecations #self_conversion #arg_convert @@ -471,6 +474,7 @@ impl<'a> FnSpec<'a> { _args: *mut _pyo3::ffi::PyObject, _kwargs: *mut _pyo3::ffi::PyObject ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = #rust_name; // Shadow the function name to avoid #3017 #deprecations #self_conversion #arg_convert @@ -489,6 +493,7 @@ impl<'a> FnSpec<'a> { _kwargs: *mut _pyo3::ffi::PyObject ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { use _pyo3::callback::IntoPyCallbackOutput; + let function = #rust_name; // Shadow the function name to avoid #3017 #deprecations #arg_convert let result = #call; diff --git a/pyo3-macros-backend/src/pymethod.rs b/pyo3-macros-backend/src/pymethod.rs index a93fe70f859..38a8df8bee9 100644 --- a/pyo3-macros-backend/src/pymethod.rs +++ b/pyo3-macros-backend/src/pymethod.rs @@ -441,9 +441,9 @@ fn impl_py_class_attribute(cls: &syn::Type, spec: &FnSpec<'_>) -> syn::Result) -> syn::Result) -> _pyo3::PyResult<_pyo3::PyObject> { + let function = #cls::#name; // Shadow the method name to avoid #3017 #deprecations let mut ret = #fncall; let owned = _pyo3::impl_::pymethods::OkWrap::wrap(ret, py); @@ -1151,12 +1152,14 @@ impl SlotDef { *extract_error_mode, return_mode.as_ref(), )?; + let name = spec.name; let associated_method = quote! { unsafe fn #wrapper_ident( #py: _pyo3::Python<'_>, _raw_slf: *mut _pyo3::ffi::PyObject, #(#arg_idents: #arg_types),* ) -> _pyo3::PyResult<#ret_ty> { + let function = #cls::#name; // Shadow the method name to avoid #3017 let _slf = _raw_slf; #body }