Skip to content

Commit

Permalink
Revert PyO3#889
Browse files Browse the repository at this point in the history
  • Loading branch information
kngwyu committed May 11, 2020
1 parent 3e61a58 commit 9f8b7cd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion guide/src/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ impl pyo3::class::methods::PyMethodsInventory for Pyo3MethodsInventoryForMyClass
self.methods
}
}
impl pyo3::class::methods::PyMethodsImpl for MyClass {
impl pyo3::class::methods::HasMethodsInventory for MyClass {
type Methods = Pyo3MethodsInventoryForMyClass;
}
pyo3::inventory::collect!(Pyo3MethodsInventoryForMyClass);
Expand Down
6 changes: 3 additions & 3 deletions pyo3-derive-backend/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ fn impl_methods_inventory(cls: &syn::Ident) -> TokenStream {
}
}

impl pyo3::class::methods::PyMethodsImpl for #cls {
impl pyo3::class::methods::HasMethodsInventory for #cls {
type Methods = #inventory_cls;
}

Expand Down Expand Up @@ -455,8 +455,8 @@ fn impl_descriptors(
Ok(quote! {
pyo3::inventory::submit! {
#![crate = pyo3] {
type ClsInventory = <#cls as pyo3::class::methods::PyMethodsImpl>::Methods;
<ClsInventory as pyo3::class::methods::PyMethodsInventory>::new(&[#(#py_methods),*])
type Inventory = <#cls as pyo3::class::methods::HasMethodsInventory>::Methods;
<Inventory as pyo3::class::methods::PyMethodsInventory>::new(&[#(#py_methods),*])
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions pyo3-derive-backend/src/pyimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub fn impl_methods(ty: &syn::Type, impls: &mut Vec<syn::ImplItem>) -> syn::Resu
Ok(quote! {
pyo3::inventory::submit! {
#![crate = pyo3] {
type TyInventory = <#ty as pyo3::class::methods::PyMethodsImpl>::Methods;
<TyInventory as pyo3::class::methods::PyMethodsInventory>::new(&[#(
type Inventory = <#ty as pyo3::class::methods::HasMethodsInventory>::Methods;
<Inventory as pyo3::class::methods::PyMethodsInventory>::new(&[#(
#(#cfg_attributes)*
#methods
),*])
Expand Down
4 changes: 2 additions & 2 deletions pyo3-derive-backend/src/pyproto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ fn impl_proto_impl(
let inventory_submission = quote! {
pyo3::inventory::submit! {
#![crate = pyo3] {
type ProtoInventory = <#ty as pyo3::class::methods::PyMethodsImpl>::Methods;
<ProtoInventory as pyo3::class::methods::PyMethodsInventory>::new(&[#(#py_methods),*])
type Inventory = <#ty as pyo3::class::methods::HasMethodsInventory>::Methods;
<Inventory as pyo3::class::methods::PyMethodsInventory>::new(&[#(#py_methods),*])
}
}
};
Expand Down
25 changes: 13 additions & 12 deletions src/class/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,28 @@ pub trait PyMethodsInventory: inventory::Collect {
fn get(&self) -> &'static [PyMethodDefType];
}

/// Implementation detail. Only to be used through the proc macros.
/// For pyclass derived structs, this trait collects method from all impl blocks using inventory.
#[doc(hidden)]
#[cfg(feature = "macros")]
pub trait PyMethodsImpl {
/// Normal methods. Mainly defined by `#[pymethod]`.
pub trait HasMethodsInventory {
type Methods: PyMethodsInventory;
}

/// Implementation detail. Only to be used through the proc macros.
/// For pyclass derived structs, this trait collects method from all impl blocks using inventory.
#[doc(hidden)]
pub trait PyMethodsImpl {
/// Returns all methods that are defined for a class.
fn py_methods() -> Vec<&'static PyMethodDefType> {
inventory::iter::<Self::Methods>
.into_iter()
.flat_map(PyMethodsInventory::get)
.collect()
Vec::new()
}
}

#[doc(hidden)]
#[cfg(not(feature = "macros"))]
pub trait PyMethodsImpl {
#[cfg(feature = "macros")]
impl<T: HasMethodsInventory> PyMethodsImpl for T {
fn py_methods() -> Vec<&'static PyMethodDefType> {
Vec::new()
inventory::iter::<T::Methods>
.into_iter()
.flat_map(PyMethodsInventory::get)
.collect()
}
}

0 comments on commit 9f8b7cd

Please sign in to comment.