Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bad span of _slf for custom receivers in #[pymethods]. #3178

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/3178.fixed.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion pyo3-macros-backend/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions tests/test_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<'_>,
Expand Down