-
Notifications
You must be signed in to change notification settings - Fork 258
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
Conversion between Java and Python collections #457
Comments
Hi, sorry for not answering before, i guess we have neglected this project quite a bit 😬 3 seems interesting, but i'm not sure how a hook system would work in pyjnius, some kind of middleware register system? so everytime an object is exchanged between java and python, it goes through a list of registered function, that are free to return the same or a different object, before the resulting object is actually sent to the java side, or delivered to the python side? I'm not sure about the ease of use of such a system, if that's what you are thinking about, and i'm a bit worried about both the performances and the debugability of apps (ab)using this feature. But maybe i'm burning a strawman, so if you want to clarify, feel free to do so. 😄 |
@tshirtman Thanks for the feedback! I'll try to find some time to dig into the pyjnius code in more detail and explore the best way to include the conversion routines. As part of that, I'll think about what a possible hook system for extensibility could look like. One PR at a time. 😄 |
My community has switched to JPype (see also #551), which does more collections-related conversions. So the chance I'll follow up on this issue is now realistically zero. Therefore, I'm closing it to avoid clutter here. |
In #295 (comment) @KeyWeeUsr writes:
For the scyjava project, I implemented conversion routines between common Java and Python data structures, including: iterables, iterators, map/dict, lists, and sets. The code can be found here. The Python-to-Java conversions are done eagerly as copies. The Java-to-Python conversions are done as new Python-side classes that extend appropriate
collections.abc
classes and implement all the appropriate functions. This allows complex Java objects to be treated more like Python objects—e.g. you can easily iterate them using Python syntax.My questions are:
Would pyjnius be interested in this functionality migrating upstream? At least as explicit conversion functions?
If so: what about passing a Python list or dict or set directly to a Java method call that expects a
List
orMap
orSet
respectively, without needing to explicitly convert to Java? To my naive eye, it looks like Convert Python array-like structures properly to Java Objects #386 by @KeyWeeUsr starts to go in this direction, although only between Python stuff and JavaObject[]
? Would the scyjava conversions just be new cases injnius_conversion.pxi
? Or somewhere else in the code? Or is it not that easy?Finally—or perhaps in lieu of (1) and (2)—it would be super slick if the supported cases could be extended by third party code. Then I could register the supported scyjava conversions with that extension mechanism, and we would not need to migrate the code into pyjnius. To be clear though, I'd love to contribute this code to pyjnius—I just need a little guidance on where to put it, and I can make a PR.
Thanks very much for all your time and effort on the pyjnius project.
The text was updated successfully, but these errors were encountered: