-
Notifications
You must be signed in to change notification settings - Fork 255
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
Reflect class (#534) #539
base: master
Are you sure you want to change the base?
Reflect class (#534) #539
Conversation
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.
LGTM
jnius/reflect.py
Outdated
|
||
|
||
# NOTE: See also comments on autoclass() | ||
def reflect_class(c, include_protected=True, include_private=True): |
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.
better call it cls
.
Also a docstring would be nice.
hm, i though the tests would be ran if i did the PR, but apparently not, because the branch is outside this repository. |
See https://github.com/terrier-org/pyterrier/blob/master/.github/workflows/push.yml#L6 for an example |
Actually: jnius_conversion.pxi, line 203: # r == 'java/lang/Character'
if r not in jclass_register: I think this is a bug. in jnius_exportclass.pxi, jclass_register is keyed using a tuple, not just the string of the classname. Also, for MetaJavaClass, the get_javaclass() defaults don't match the constructor defaults for classparams. I think these need to be a constant (cc @hx2A). |
Further WIP committed.
I will return to this branch later this week to address the key part about getting the Class object |
It seems I missed a change I should have made when I modified |
hi @hx2A . Sure yes. Can you comment on the discrepancy in MetaJavaClass: constructor vs the get_javaclass(). I think having constants that we could refer to in autoclass() and elsewhere should fix this all. |
Yes. I reviewed the code and I see I made this mistake. When I changed the default params in the The default values are supposed to be |
you probably can't, but you can push your branch and he can pull from it. |
I made the changes and the unit tests pass. It wasn't a big change. I apologize for not coding it this way in the first place. I'm a little bit confused with the git commands I need to do to properly collaborate here. Below is what I did; perhaps you can tell me what I need to do next. First I checked out @cmacdonald 's branch so there wouldn't be merge issues.
Then I did the coding changes and ran the unit tests. I pushed the changes to my forked repo with this:
But on github I don't see a branch, or anything else to suggest this has been pushed to my origin. Do I need to create a new branch or something? This is my current status:
Obviously I'm not a pro at using git. |
|
That didn't work because I was in a detached head state. I had to create a branch first.
Now there is a branch on github you can pull from. |
Thanks @hx2A, I have some feedback on fix_20200526:
|
I changed them to These are defined in |
These are defined in jnius/jnius_export_class.pxi. Is there a better place for them?
I think we should have a test ensuring that this behaves as expected autoclass() an object, and check that the MetaJavaClass.get_javaclass(cls_name) function returns. cls_name = "bla.something.relatively.rare.in.jvm"
if MetaJavaClass.get_javaclass(cls_name) is not None:
self.skipTest("%s already loaded - has this test run more than once?" % cls_name)
self.assertIsNotNone( autoclass(cls_name) )
self.assertIsNotNone( MetaJavaClass.get_javaclass(cls_name) ) |
Unittest added to tests/test_reflect.py. The code looks like this:
|
Thank you @hx2A, I will merge into this branch. |
Wait, I just made a minor change to the branch |
Slight improvement:
|
Hi @tshirtman and @AndreMiras. Some notes:
I want to test this a bit further, but now would be good time for re-review. |
PS: A demanding suite of tests that can be use for timings might be a Good Thing. |
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.
Part I am least happy with: jnius_conversion.pxi checking for find_javaclass() raising an exception - I think we should pass find_javaclass() a flag about exception handling.
Indeed, it would be better if at least the exception we want to handle there was explicit, instead of catching any exception, bare excepts are a common source of bugs.
Also in jnius_conversion.pxi, could we do a object.getClass() wholly using the proper JNI method, rather than fully instantiating an Object, then throwing it away once we have called getClass()? (And does this code leak a LocalRef?)
I think that would be great, yes, not sure why/if the current way is needed, but that does indeed look suboptimal.
jnius/reflect.py
Outdated
Auto-reflects a class based on an instance of its class. | ||
|
||
Parameters: | ||
cls_object (str): a Python instance of a java.lang.Class 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.
it's not an str
.
self.assertIsNotNone(instance) | ||
|
||
|
||
def test_dynamic_jar(self): |
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.
that's pretty cool :)
Looks really cool, looking forward to merging :) |
Co-authored-by: Gabriel Pettier <[email protected]>
…() on the case of duplicate methods
This patch addresses the feedback. Salient commentary:
Hopefully one more round should close this. |
I've tried out this branch to try to see if it would fix an issue I have (autoclass finding MyFirstClass.java but not MySecondClass.java despite them being next to each other), but my application crashes on launch if I use pyjnius from @cmacdonald's branch. It might be coming from my side, but just thought I'd let you know:
Only difference with a working application is the pyjnius version (I'm now back to master and all is well except for the issue mentioned earlier). |
Thanks. I'm not an Android person, so testing on Android is a problem for me. Is there more of the stacktrace that can show where in Jnius it failed? You said it fails "on launch" - what was the python code? |
There's also a stack trace of all threads but nothing relates to pyjnius and there is unfortunately no more information concerning the exact exception location. Unfortunately that is a pretty big application which makes a few pyjnius references and I cannot share its source code, but it's failing before the app has even loaded (there are some globals defined with pyjnius as well so just loading the Python file could trigger the issue?). As you can see from the log this is happening right after "184 symbols loaded" which is still deep inside Kivy's initialization routines. A normal log looks like this:
See that no application code has ran yet at the point where it crashed with your branch. Sorry this is not very helpful! |
I did some testing on this branch with my project and everything looked OK. This branch lacks the Is there anything I can do to help move this along? |
I can rebase this week. Could you review some of the other outstanding PRs Jim? |
@cmacdonald I will do that |
No description provided.