Skip to content

Commit 3a4710a

Browse files
Icxoludavidhewitt
authored andcommitted
fix unused_imports warning for IsOption probe (#5002) (#5030)
1 parent 158bd31 commit 3a4710a

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

newsfragments/5030.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes accidentally emitting `unused_imports` lint in `macro_rules` context.

pyo3-macros-backend/src/params.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ pub(crate) fn impl_regular_arg_param(
238238

239239
// Use this macro inside this function, to ensure that all code generated here is associated
240240
// with the function argument
241-
let use_probe = quote!(use #pyo3_path::impl_::pyclass::Probe as _;);
241+
let use_probe = quote! {
242+
#[allow(unused_imports)]
243+
use #pyo3_path::impl_::pyclass::Probe as _;
244+
};
242245
macro_rules! quote_arg_span {
243246
($($tokens:tt)*) => { quote_spanned!(arg.ty.span() => { #use_probe $($tokens)* }) }
244247
}

pyo3-macros-backend/src/pymethod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ pub fn impl_py_setter_def(
701701
let holder = holders.push_holder(span);
702702
let ty = field.ty.clone().elide_lifetimes();
703703
quote! {
704+
#[allow(unused_imports)]
704705
use #pyo3_path::impl_::pyclass::Probe as _;
705706
let _val = #pyo3_path::impl_::extract_argument::extract_argument::<
706707
_,
@@ -1205,6 +1206,7 @@ fn extract_object(
12051206
let holder = holders.push_holder(Span::call_site());
12061207
let ty = arg.ty().clone().elide_lifetimes();
12071208
quote! {{
1209+
#[allow(unused_imports)]
12081210
use #pyo3_path::impl_::pyclass::Probe as _;
12091211
#pyo3_path::impl_::extract_argument::extract_argument::<
12101212
_,

tests/ui/pyclass_probe.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(unused_imports)]
12
use pyo3::prelude::*;
23

34
#[pyclass]
@@ -17,4 +18,20 @@ fn probe(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
1718
Ok(())
1819
}
1920

21+
#[pyclass]
22+
struct Check5029();
23+
24+
macro_rules! impl_methods {
25+
($name:ident) => {
26+
#[pymethods]
27+
impl Check5029 {
28+
fn $name(&self, _value: Option<&str>) -> PyResult<()> {
29+
Ok(())
30+
}
31+
}
32+
};
33+
}
34+
35+
impl_methods!(some_method);
36+
2037
fn main() {}

0 commit comments

Comments
 (0)