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.
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
Function for converting Python values to an explicit Java type #128
Function for converting Python values to an explicit Java type #128
Changes from 12 commits
9bdbaeb
06df869
d599bf0
1676e46
d43e8df
20444d6
5a3fdf0
ea60b1f
61bde34
877a99b
36ed7a0
b49090b
3dea91c
0996fac
2794f6b
e20757b
525362d
2d252c3
c25ab7c
eaff9d6
dc161cf
d204645
1d884a8
c61869d
010feaf
b060d17
bdd1f72
efab329
4182956
f364d46
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Do we need this? You can currently do
type(jobj).jclass.getName()
. This does involve a boundary crossing though.If we think it's important to have w/o boundary crossing, and explicitly meant for jobj types, instead of adding
jpy
top level method, we can attach an attribute to the JPy_JType. From end user perspective, it would look something like:would be appropriate. See logic in
JType_AddClassAttribute
.I'm actually surprised that
isn't the full classname; https://docs.python.org/3/c-api/typeobj.html#tp-slots hints that that should be tp_name.
And our code has this:
Something screwy is going on though:
I'll do some further digging, b/c this seems odd...
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.
https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_name
Looks like
is the way to get the java class name; this doesn't quite work for primitives (not sure what we expect to happen w/ primitives).
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.
I don't think primitives apply — I don't think you can wrap an unboxed primitive value in a
JPy_JObj
.I got rid of this method and added
type(obj).jclassname
.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.
This is cool - previously, we could do this, it just required explicit java code:
I'm assuming these are the semantics you are after?
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.
Yeah, basically I had two parallel lists, one of java types and one of python values (in practice strings/numbers), and I wanted to stick the python values into a java
Object[]
with the given Java type, but numbers I wanted asLong
were getting converted toByte
. I could have just used the constructors explicitly but that's not as clean, and it seems worthwhile to exposeJType_ConvertPythonToJavaObject
anyway.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.
I am not too crazy about the name
as_jobj
, wouldconv
be better?From what I can gather, I do like that I can now create a org.jpy.PyObject in Python directly.
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.
I'm definitely open to changing it. I went with
as_jobj
because it ultimately callsJPy_AsJObjectWithType
, and I thought having 'obj' in the name explicitly could be helpful because conversion in Java is a distinct concept (though a related one) that also involves Java primitives.@devinrsmith what do you think?
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.
I think "as" gives off the wrong semantic notion, somewhat akin to zero-cost. While the same could be said about
JPy_AsJObjectWithType
, that's lower level and not exposed to the end user. Also, it calls down intoJType_ConvertPythonToJavaObject
.I'm also not the biggest fan of trying to save a few characters; my vote would be for
jpy.convert
instead ofjpy.conv
/jpy.as_jobj
.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.
JPy_FROM_JVOID
is meant to be used in combination withvoid.class
type; it's not appropriate to use it in these contexts.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.
Replaced the handful of
Py_BuildValue()
s I changed with a newJPy_PY_NONE()
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.
This is not appropriate to use here unless we are converting from a null java object.
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.
Ditto
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.
We should delete the global ref if this happens.
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 — fixed