Skip to content

Commit 26b23af

Browse files
committed
fix(pyo3-macros): allow pyclass named Probe
The `*` import was shadowing the name of the pyclass. Fixes #4792.
1 parent 3ffad5a commit 26b23af

2 files changed

Lines changed: 30 additions & 15 deletions

File tree

pyo3-macros-backend/src/pyclass.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,13 +3010,13 @@ impl<'a> PyClassImplsBuilder<'a> {
30103010
type BaseNativeType = #base_nativetype;
30113011

30123012
fn items_iter() -> #pyo3_path::impl_::pyclass::PyClassItemsIter {
3013-
use #pyo3_path::impl_::pyclass::*;
3014-
let collector = PyClassImplCollector::<Self>::new();
3015-
static INTRINSIC_ITEMS: PyClassItems = PyClassItems {
3013+
use #pyo3_path::types::PyAnyMethods as _;
3014+
let collector = #pyo3_path::impl_::pyclass::PyClassImplCollector::<Self>::new();
3015+
static INTRINSIC_ITEMS: #pyo3_path::impl_::pyclass::PyClassItems = #pyo3_path::impl_::pyclass::PyClassItems {
30163016
methods: &[#(#default_method_defs),*],
30173017
slots: &[#(#default_slot_defs),* #(#freelist_slots),*],
30183018
};
3019-
PyClassItemsIter::new(&INTRINSIC_ITEMS, #pymethods_items)
3019+
#pyo3_path::impl_::pyclass::PyClassItemsIter::new(&INTRINSIC_ITEMS, #pymethods_items)
30203020
}
30213021

30223022
const RAW_DOC: &'static ::std::ffi::CStr = #doc;

tests/ui/pyclass_probe.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
#![deny(unused_imports)]
22
use pyo3::prelude::*;
33

4-
#[pyclass]
5-
pub struct Probe {}
6-
7-
#[pymethods]
8-
impl Probe {
9-
#[new]
10-
fn new() -> Self {
11-
Self {}
4+
#[pymodule]
5+
mod probe_no_fields {
6+
use pyo3::prelude::*;
7+
#[pyclass]
8+
pub struct Probe {}
9+
10+
#[pymethods]
11+
impl Probe {
12+
#[new]
13+
fn new() -> Self {
14+
Self {}
15+
}
1216
}
1317
}
1418

1519
#[pymodule]
16-
fn probe(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
17-
m.add_class::<Probe>()?;
18-
Ok(())
20+
mod probe_with_fields {
21+
use pyo3::prelude::*;
22+
#[pyclass(get_all)]
23+
pub struct Probe {
24+
field: u8,
25+
}
26+
27+
#[pymethods]
28+
impl Probe {
29+
#[new]
30+
fn new() -> Self {
31+
Self { field: 0 }
32+
}
33+
}
1934
}
2035

2136
#[pyclass]

0 commit comments

Comments
 (0)