Skip to content

Use return types, not Dicts#324

Merged
timholy merged 2 commits into
masterfrom
teh/return-types
May 26, 2026
Merged

Use return types, not Dicts#324
timholy merged 2 commits into
masterfrom
teh/return-types

Conversation

@timholy

@timholy timholy commented May 26, 2026

Copy link
Copy Markdown
Member

ImageView has historically returned all the GUI-state info as a Dict. This has caused several problems, of which perhaps the most severe stems from the default REPL-printing of Dicts which would try to print out the entire image. This creates a dedicated type of each major entry point, and custom show methods allow us to determine what gets printed.

This is split into two commits. The first changes the code and adds deprecation shims for the old code. No tests are changed. This establishes that this PR is fundamentally non-breaking, thanks to the shims. Downstream consumers should run with julia --depwarn=yes and fix the deprecation warnings with a [compat] set to 0.13.2.

The second commit migrates the README and tests to the new API. Forward-looking packages can use this API, but ImageView's [compat] should be no lower than 0.13.2.

Fixes #292

timholy and others added 2 commits May 26, 2026 07:33
Introduce `ImageDisplay`, `ImageViewGUI`, and `ImageROI` as the
return types of `imshow`, `imshow_gui`, and the low-level
`imshow(canvas, ...)` respectively. `ImageDisplay` forwards field
access to its nested `gui` and `roi` so users can write `disp.window`,
`disp.zoomregion`, `disp.image_roi`, etc. The custom `show` methods
print only a compact summary — never the underlying image array —
which fixes the long-standing usability problem where forgetting a
trailing semicolon at the REPL caused multi-second hangs while
Julia's default dict `show` recursively printed the entire image.

The concrete types also give downstream packages a dispatch target;
extensions that need to support multiple plotting backends can now
write methods like `f(::ImageView.ImageDisplay, ...)`.

The pre-existing string-key API (`guidict["gui"]["window"]`,
`guidict["roi"]["zoomregion"]`, etc.) is preserved through a
deprecation shim implemented via `Base.getindex` on each new struct;
each call emits a `Base.depwarn`. This commit deliberately leaves
`test/` and `README.md` untouched — the existing test suite is the
correctness check that the shim faithfully reproduces the old API.

Isolates the legacy string-key indexing methods so the next breaking
release can remove the shim by deleting one file and the corresponding
`include`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Converts every call site that indexes the `imshow` return value by
string to the new struct field syntax (e.g. `result["gui"]["window"]`
→ `result.window`, `result["roi"]["zoomregion"]` → `result.zoomregion`,
`result["roi"]["image roi"]` → `result.image_roi`). Updates the
README's tutorial and script-usage examples, the `imshow`/`imshow_gui`/
`scalebar` docstrings, and adds a NEWS.md entry describing the change
and the deprecation shim. The shim itself is untouched — the legacy
string-key API continues to work with a `Base.depwarn`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@timholy timholy changed the title Add return types, not Dicts Use return types, not Dicts May 26, 2026
@timholy timholy merged commit a0d7add into master May 26, 2026
14 of 15 checks passed
@timholy timholy deleted the teh/return-types branch May 26, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slow with large images

1 participant