-
Notifications
You must be signed in to change notification settings - Fork 784
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -115,15 +115,7 @@ impl PySetterDef { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
#[doc(hidden)] // Only to be used through the proc macros, use PyMethodsProtocol in custom code | ||||||||||
/// This trait is implemented for all pyclass so to implement the [PyMethodsProtocol] | ||||||||||
/// through inventory | ||||||||||
pub trait PyMethodsInventoryDispatch { | ||||||||||
/// This allows us to get the inventory type when only the pyclass is in scope | ||||||||||
type InventoryType: PyMethodsInventory; | ||||||||||
} | ||||||||||
|
||||||||||
#[doc(hidden)] // Only to be used through the proc macros, use PyMethodsProtocol in custom code | ||||||||||
#[doc(hidden)] // Only to be used through the proc macros | ||||||||||
/// Allows arbitrary pymethod blocks to submit their methods, which are eventually collected by pyclass | ||||||||||
pub trait PyMethodsInventory: inventory::Collect { | ||||||||||
/// Create a new instance | ||||||||||
|
@@ -133,20 +125,15 @@ pub trait PyMethodsInventory: inventory::Collect { | |||||||||
fn get_methods(&self) -> &'static [PyMethodDefType]; | ||||||||||
} | ||||||||||
|
||||||||||
/// The implementation of this trait defines which methods a Python type has. | ||||||||||
/// | ||||||||||
/// For pyclass derived structs this is implemented by collecting all impl blocks through inventory | ||||||||||
pub trait PyMethodsProtocol { | ||||||||||
/// Returns all methods that are defined for a class | ||||||||||
fn py_methods() -> Vec<&'static PyMethodDefType>; | ||||||||||
} | ||||||||||
#[doc(hidden)] // Only to be used through the proc macros | ||||||||||
/// For pyclass derived structs, this trait collects method from all impl blocks using inventory. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually I put attributes after doc? Maybe it doesn't work for
Suggested change
|
||||||||||
pub trait PyMethodsImpl { | ||||||||||
davidhewitt marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
/// Normal methods, mainly defined by `#[pymethod]`. | ||||||||||
type Methods: PyMethodsInventory; | ||||||||||
|
||||||||||
impl<T> PyMethodsProtocol for T | ||||||||||
where | ||||||||||
T: PyMethodsInventoryDispatch, | ||||||||||
{ | ||||||||||
/// Returns all methods that are defined for a class | ||||||||||
fn py_methods() -> Vec<&'static PyMethodDefType> { | ||||||||||
inventory::iter::<T::InventoryType> | ||||||||||
inventory::iter::<Self::Methods> | ||||||||||
.into_iter() | ||||||||||
.flat_map(PyMethodsInventory::get_methods) | ||||||||||
.collect() | ||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Longer name is also fine, just wondered if I could find a shorter one which worked.
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
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.