-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
pyproto: remove inventory from implementation #1328
Conversation
12b4605
to
e16bea5
Compare
Awesome, thank you so much!
Aren't these changes actually unrelated to removing inventory? I like the way it flattens the definitions, though. At a glance, this PR looks almost OK for me. |
Sort of - I wanted the new specialised traits to provide
I think I can hard-code some simplifications about the paths in |
I pushed a commit which puts the module path on the top-level As I think these defs might have to change again to implement #1206 in the way I imagine, I think it's not worth doing further refactoring right now. |
830b9dc
to
022c626
Compare
@kngwyu ok if I merge this today before the release? It technically "breaks" any code using the |
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.
Sure, I noted some additional suggestions.
66c090e
to
9e7fa40
Compare
👍 will merge this shortly, then rebase the release and push it out! |
This is a refactoring for
#[pyproto]
which uses dtolnay specialization instead of inventory as the underlying implementation.The dtolnay specialization is done for a type
PyClassProtocols<T: PyClass>
. There are traitsPyObjectProtocolSlots<T>
etc. which are what get specialized. The default implementation isPyObjectProtocolSlots<T> for &'_ PyClassProtocols<T>
, and the specialized implementation isPyObjectProtocolSlots<T> for PyClassProtocols<T>
.The traits with slot getter methods have been replaced by free functions to implement the slots, which the pyproto macro code directly uses.
It works out as slightly fewer LOC and also because all the protocols are known at compile time, the compiler should be able to optimise pyclass initialization better.
At the moment we lost the type checking we had with
TypedSlot
. If that's a concern I think I can reintroduce a type check in the slot defs in the macro code.Follow-ups:
inventory
an optional feature where it's only needed when users want multiple#[pymethods]
blocks for a single PyClass. That'd be a nice simplification to remove overheads.