-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Make dictionary class and list class optable #16
Conversation
2a74a29
to
4d05f9a
Compare
Thank you for this PR. I can understand the use-case you are aiming to solve by introducing this new type. However I am not convinced I support it for this library. For example, if you are using By introducing this new type, you are able to remove this constraint. However, there are new problems, for example it's no longer possible in Python to json-encode the output of this library by default. Many of the tests in this library are failing as a result. I would be more okay with this change if there was a way to opt-in to it rather than make this by default. I think most users would prefer to have As this is, I'm afraid I'm unenthusiastic about merging, however I'm always open to being persuaded otherwise... |
@davidhewitt Thanks for the feedback! Considering Wasn't thinking about the defaults during making it. Would you consider adding it if i make it a cargo-feature? |
A cargo feature is a great start so that users who don't need it don't pay for it. However, this also needs to be a different API e.g. Tbh I would be more comfortable with this addition if it was built so that users could swap the target |
I see. What do you think about implementing it as generic then? We could expose some trait (which we implement for |
A generic sounds a lot like the kind of thing I was envisioning. It should be easier to write depythonize (as python input can be duck-typed). A full trait description would probably be necessary for pythonize. |
ffe142a
to
7b2003e
Compare
@davidhewitt Sorry for delay. Updated pr with traits for List and Dict. Now you can supply custom dict and list with |
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.
🚀 Thanks for revisiting this! The new iteration looks great, overall I'm really happy with the flexibility this gives.
I'm a bit tired tonight so haven't managed to give as much detail to the review as I would have liked, however I have a few initial suggestions. I think that they should simplify the code a little, and then I'll aim to give this once final review (with the intention to merge).
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.
Thanks very much, this is shaping up well.
I've given this a detailed read through and overall am happy with how this expands the functionality of pythonize
.
I think the traits are more complicated than they need to be, so I think there might be a couple of rounds of iteration still to go here to simplify what pythonize
asks users to implement. Once the traits are good, I'm all for merging and releasing this!
In particular I think the PyArray
trait (which I think could be called PythonizeSequence
) already can be simplified a lot, and if we build a PyMapping
helper (see comment below) then we can do a similar thing for PyDictionary
.
Codecov Report
@@ Coverage Diff @@
## main #16 +/- ##
=======================================
Coverage ? 82.40%
=======================================
Files ? 4
Lines ? 938
Branches ? 0
=======================================
Hits ? 773
Misses ? 165
Partials ? 0 Continue to review full report at Codecov.
|
Signed-off-by: i1i1 <[email protected]>
950caf1
to
889987b
Compare
@davidhewitt sorry for delay. Here is a new version of pythonize which uses both mapping and sequence protocol as we discussed (Resolved previous issues also). There are 2 commits here:
|
c4ba306
to
4be0c34
Compare
Signed-off-by: i1i1 <[email protected]>
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.
Thanks for the many many rounds of iteration this PR has gone through, I'm satisfied that this new implementation should provide a nice way for users to supply custom classes without adding too much baggage to the pythonize
core.
Really great work 🎉
I'll release this once PyO3 0.15 is out and we can update pythonize
to depend on it fully.
Main motivation for dictionary and list types is to be able to send this kind of datastructures:
So here BTreeMap has key type as Id which will be mapped to python dictionary which is not hashable. So in order to be able to deserialize more things from python it would be nice to replace PyDict with this dict.