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

refactor: simpler pyclass internals #2157

Merged
merged 4 commits into from Feb 9, 2022

Conversation

davidhewitt
Copy link
Member

Just makes a few cleanups to the #[pyclass] internals which I noticed were possible the other day:

Overall seems like a nice simplification; makes the machinery of the pyclass internals a bit more uniform. Also reduces llvm-lines count of pytests crate by around 1%. So nothing major, still seems nice.

Comment on lines +196 to 199
impl #cls {
#[doc(hidden)]
#wrapper
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Realising that the wrapper could be an associated method of the struct is interesting for a couple of reasons:

  • We have some rather ugly code to recursively replace_self (in method argument types and return values) - if all Pymethod wrappers were placed on the struct like this, we won't need it.
  • In addition, because the struct is a shared namespace, we could use this safeguard against multiple Python definitions with the same name. (That's exactly why I did it here; so that #[new] can only be implemented once.)

I'll probably play around with this in a follow-up PR.

@davidhewitt davidhewitt merged commit be31ca9 into PyO3:main Feb 9, 2022
@davidhewitt davidhewitt deleted the simpler-default-items branch February 9, 2022 09:04
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.

None yet

1 participant