Skip to content

Avoid converting objects when not necessary#60

Merged
ctrueden merged 4 commits intomainfrom
avoid-unnecessary-conversion
May 31, 2023
Merged

Avoid converting objects when not necessary#60
ctrueden merged 4 commits intomainfrom
avoid-unnecessary-conversion

Conversation

@gselzer
Copy link
Copy Markdown
Member

@gselzer gselzer commented May 26, 2023

to_python and to_java assume that their arguments are in the other language. But, as described in imagej/napari-imagej#220, Converters have to defensively program against arguments that are already in the desired language.

This PR does a sanity check on the argument to convert, ensuring that the argument to a to_java call is actually a python data structure, and that the argument to a to_python call is actually a java data structure. When the argument is not, this change will save us a bit of computation at the least, and save us from some errors in more severe cases.

@gselzer gselzer added the bug label May 26, 2023
@gselzer gselzer requested review from ctrueden and hinerm May 26, 2023 19:25
@gselzer gselzer self-assigned this May 26, 2023
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 26, 2023

Codecov Report

Merging #60 (1d1e50a) into main (18294c4) will increase coverage by 1.02%.
The diff coverage is 88.57%.

❗ Current head 1d1e50a differs from pull request most recent head bab6145. Consider uploading reports for the commit bab6145 to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main      #60      +/-   ##
==========================================
+ Coverage   54.70%   55.72%   +1.02%     
==========================================
  Files          11       11              
  Lines        1179     1213      +34     
==========================================
+ Hits          645      676      +31     
- Misses        534      537       +3     
Impacted Files Coverage Δ
tests/test_convert.py 89.71% <87.09%> (-0.37%) ⬇️
src/scyjava/_convert.py 42.55% <100.00%> (+1.01%) ⬆️

ctrueden and others added 4 commits May 31, 2023 15:03
This is accomplished by keeping the converters sorted by priority,
then invoking them one by one in order until we find a working one.

Co-authored-by: Gabriel Selzer <gjselzer@wisc.edu>
And make str(Converter) yield a representation helpful for debugging.
The DEBUG level is too granular for normal use. In particular, the
message "The JVM is already running" appears many times when running in
debug mode. We could change that message to print only in JPYPE mode,
but I think INFO is a better fit for CI generally anyway.
@ctrueden ctrueden force-pushed the avoid-unnecessary-conversion branch from 010ffd3 to 3b5c27a Compare May 31, 2023 20:03
@ctrueden ctrueden merged commit 932e76d into main May 31, 2023
@ctrueden ctrueden deleted the avoid-unnecessary-conversion branch May 31, 2023 20:38
ctrueden added a commit to imagej/napari-imagej that referenced this pull request Jul 25, 2023
And bump minimum scyjava version to 1.9.1.

As of scyjava 1.9.1, the work from scijava/scyjava#60 is integrating,
meaning such defensive checks around conversion are no longer necessary.

This reverts commit 85f0d5c,
titled "Work around jpype convert limitation", and closes #220.

It also removes some other usages of isjava, which are also not needed.
ctrueden added a commit to imagej/napari-imagej that referenced this pull request Jul 25, 2023
And bump minimum scyjava version to 1.9.1.

As of scyjava 1.9.1, the work from scijava/scyjava#60 is integrated,
meaning such defensive checks around conversion are no longer necessary.

This reverts commit 85f0d5c,
titled "Work around jpype convert limitation", and closes #220.

It also removes some other usages of isjava, which are also not needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants