Fix a span site of `_slf` for custom receivers.

This commit is contained in:
Kang Seonghoon 2023-05-23 10:25:57 +09:00
parent a3c4fd2fa0
commit 24343f2caa
3 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1 @@
Fix a compile error when `#[pymethods]` items come from somewhere else (for example, as a macro argument) and a custom receiver like `Py<Self>` is used.

View File

@ -189,10 +189,11 @@ impl SelfType {
}
}
SelfType::TryFromPyCell(span) => {
let _slf = quote! { _slf };
quote_spanned! { *span =>
let _cell = #cell;
#[allow(clippy::useless_conversion)] // In case _slf is PyCell<Self>
let _slf = ::std::convert::TryFrom::try_from(_cell)?;
let #_slf = ::std::convert::TryFrom::try_from(_cell)?;
}
}
}

View File

@ -1470,6 +1470,33 @@ issue_1506!(
) {
}
fn issue_1506_mut(
&mut self,
_py: Python<'_>,
_arg: &PyAny,
_args: &PyTuple,
_kwargs: Option<&PyDict>,
) {
}
fn issue_1506_custom_receiver(
_slf: Py<Self>,
_py: Python<'_>,
_arg: &PyAny,
_args: &PyTuple,
_kwargs: Option<&PyDict>,
) {
}
fn issue_1506_custom_receiver_explicit(
_slf: Py<Issue1506>,
_py: Python<'_>,
_arg: &PyAny,
_args: &PyTuple,
_kwargs: Option<&PyDict>,
) {
}
#[new]
fn issue_1506_new(
_py: Python<'_>,