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

Unify PyMethodsInventoryDispatch and PyMethodsProtocol #889

Merged
merged 2 commits into from
May 2, 2020

Conversation

kngwyu
Copy link
Member

@kngwyu kngwyu commented May 2, 2020

PyMethodProtocol is exposed as a public API, but it is actually really difficult to use without proc-macro.
So I decided to unify PyMethodsInventoryDispatch and PyMethodsProtocol, yielding PyMethodsImpl.

Since we need more inventory-related types to remove specialization, I think we need this kind of simplification not to make our code too complex.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a nice simplification! I had a couple of ideas for names, ignore if you prefer what is already there.

@@ -213,7 +213,7 @@ fn parse_descriptors(item: &mut syn::Field) -> syn::Result<Vec<FnType>> {
fn impl_inventory(cls: &syn::Ident) -> TokenStream {
// Try to build a unique type that gives a hint about it's function when
// it comes up in error messages
let name = cls.to_string() + "GeneratedPyo3Inventory";
let name = format!("Pyo3MethodsInventoryFor{}", cls);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let name = format!("Pyo3MethodsInventoryFor{}", cls);
let name = format!("PyMethodsOf{}", cls);

Longer name is also fine, just wondered if I could find a shorter one which worked.

Copy link
Member Author

@kngwyu kngwyu May 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a generated struct, I think it's better if a user can understand that this is generated from the name if he or she uses cargo expand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. PyO3GeneratedMethodsFor{} ? Your choice of name is also fine.

src/class/methods.rs Show resolved Hide resolved
Comment on lines 128 to 129
#[doc(hidden)] // Only to be used through the proc macros
/// For pyclass derived structs, this trait collects method from all impl blocks using inventory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually I put attributes after doc? Maybe it doesn't work for #[doc(hidden)]

Suggested change
#[doc(hidden)] // Only to be used through the proc macros
/// For pyclass derived structs, this trait collects method from all impl blocks using inventory.
/// For pyclass derived structs, this trait collects method from all impl blocks using inventory.
#[doc(hidden)] // Only to be used through the proc macros

@davidhewitt
Copy link
Member

We probably need a CHANGELOG entry for removal / hiding of PyMethodsProtocol?

@kngwyu kngwyu merged commit 17cf97d into PyO3:master May 2, 2020
kngwyu added a commit to kngwyu/pyo3 that referenced this pull request May 11, 2020
kngwyu added a commit to kngwyu/pyo3 that referenced this pull request May 11, 2020
kngwyu added a commit that referenced this pull request May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants