Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/5837.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow pyclass named `Probe` with `get_all` fields.
13 changes: 8 additions & 5 deletions pyo3-macros-backend/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2829,7 +2829,11 @@ impl<'a> PyClassImplsBuilder<'a> {
};

let (pymethods_items, inventory, inventory_class) = match self.methods_type {
PyClassMethodsType::Specialization => (quote! { collector.py_methods() }, None, None),
PyClassMethodsType::Specialization => (
quote! {{ use #pyo3_path::impl_::pyclass::PyMethods as _; collector.py_methods() }},
None,
None,
),
PyClassMethodsType::Inventory => {
// To allow multiple #[pymethods] block, we define inventory types.
let inventory_class_name = syn::Ident::new(
Expand Down Expand Up @@ -3010,13 +3014,12 @@ impl<'a> PyClassImplsBuilder<'a> {
type BaseNativeType = #base_nativetype;

fn items_iter() -> #pyo3_path::impl_::pyclass::PyClassItemsIter {
use #pyo3_path::impl_::pyclass::*;
let collector = PyClassImplCollector::<Self>::new();
static INTRINSIC_ITEMS: PyClassItems = PyClassItems {
let collector = #pyo3_path::impl_::pyclass::PyClassImplCollector::<Self>::new();
static INTRINSIC_ITEMS: #pyo3_path::impl_::pyclass::PyClassItems = #pyo3_path::impl_::pyclass::PyClassItems {
methods: &[#(#default_method_defs),*],
slots: &[#(#default_slot_defs),* #(#freelist_slots),*],
};
PyClassItemsIter::new(&INTRINSIC_ITEMS, #pymethods_items)
#pyo3_path::impl_::pyclass::PyClassItemsIter::new(&INTRINSIC_ITEMS, #pymethods_items)
}

const RAW_DOC: &'static ::std::ffi::CStr = #doc;
Expand Down
37 changes: 26 additions & 11 deletions tests/ui/pyclass_probe.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
#![deny(unused_imports)]
use pyo3::prelude::*;

#[pyclass]
pub struct Probe {}

#[pymethods]
impl Probe {
#[new]
fn new() -> Self {
Self {}
#[pymodule]
mod probe_no_fields {
use pyo3::prelude::*;
#[pyclass]
pub struct Probe {}

#[pymethods]
impl Probe {
#[new]
fn new() -> Self {
Self {}
}
}
}

#[pymodule]
fn probe(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Probe>()?;
Ok(())
mod probe_with_fields {
use pyo3::prelude::*;
#[pyclass(get_all)]
pub struct Probe {
field: u8,
}

#[pymethods]
impl Probe {
#[new]
fn new() -> Self {
Self { field: 0 }
}
}
}

#[pyclass]
Expand Down
Loading