Annotate open_geotiff(source) as str | BinaryIO (#1754)#1758
Merged
brendancol merged 1 commit intoMay 13, 2026
Conversation
The api-consistency sweep on 2026-05-12 found a parameter-annotation gap on open_geotiff(source): the docstring documents "str or binary file-like" and the runtime accepts BytesIO, but the signature has no annotation. Sibling reader functions (read_geotiff_gpu, read_geotiff_dask, read_vrt) all annotate source: str because they reject file-like sources. The writer entry points (to_geotiff, write_geotiff_gpu) carry path: str | BinaryIO for the same file-like-or-string surface that open_geotiff exposes. PR #1654 annotated window, path, and on_gpu_failure across the public geotiff surface but missed source on open_geotiff. This PR closes that gap. test_signature_annotations_1654.py picks up four new pins: - open_geotiff(source) must accept both str and BinaryIO - read_geotiff_dask, read_geotiff_gpu, read_vrt stay str-only - a runtime smoke test that a BytesIO buffer round-trips through open_geotiff Annotation-only change; no runtime behaviour, no defaults, no kwarg renames. BinaryIO is already imported under TYPE_CHECKING in xrspatial/geotiff/__init__.py from PR #1654. Also updates the api-consistency sweep state CSV with the v3 row for geotiff.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR completes a public API type-hint parity fix in xrspatial.geotiff by annotating open_geotiff(source, ...) to reflect its documented and supported ability to accept either a string path/URI or a binary file-like object (e.g., io.BytesIO). It also adds regression tests to pin the source annotations across the reader entry points and a small runtime smoke test ensuring BytesIO inputs continue to work.
Changes:
- Annotate
open_geotiff(source)asstr | BinaryIO(consistent with docstring and runtime behavior). - Add tests that pin
sourceannotations foropen_geotiff,read_geotiff_dask,read_geotiff_gpu, andread_vrt, plus a runtimeBytesIOsmoke test. - Update the API-consistency sweep state CSV to record the resolved finding.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
xrspatial/geotiff/__init__.py |
Adds `source: str |
xrspatial/geotiff/tests/test_signature_annotations_1654.py |
Adds annotation “pins” for source across reader functions and a runtime test verifying open_geotiff(BytesIO(...)) works. |
.claude/sweep-api-consistency-state.csv |
Records sweep v3 finding (#1754) as filed and fixed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #1754. The api-consistency sweep on 2026-05-12 found that
open_geotiff(source, ...)lacks astr | BinaryIOtype annotationeven though the docstring documents
str or binary file-likeand theruntime accepts BytesIO buffers. Sibling reader functions
(
read_geotiff_gpu,read_geotiff_dask,read_vrt) are annotatedsource: strbecause they reject file-like sources. The writer entrypoints (
to_geotiff,write_geotiff_gpu) carrypath: str | BinaryIOfor the same file-like-or-string surface that
open_geotiffexposes.PR #1654 closed annotation gaps across
window,path, andon_gpu_failurebut skippedsourceonopen_geotiff. This PRfinishes the job.
Detail
xrspatial/geotiff/__init__.py: annotateopen_geotiff(source: str | BinaryIO, ...).BinaryIOis alreadyimported under
TYPE_CHECKINGin this module since PR Public geotiff API: type annotations missing on window / path / on_gpu_failure #1654, so theruntime import cost stays at zero with
from __future__ import annotations.xrspatial/geotiff/tests/test_signature_annotations_1654.py: fournew pins covering
sourceon all four reader entry points(
open_geotiffaccepts both str and BinaryIO; the dedicated readersstay str-only), plus a runtime smoke test that a BytesIO source
round-trips through
open_geotiff..claude/sweep-api-consistency-state.csv: v3 sweep row with thefinding metadata.
Annotation-only change. No runtime behaviour, no defaults, no kwarg
renames. No deprecation impact.
Test plan
pytest xrspatial/geotiff/tests/test_signature_annotations_1654.py -vpasses all 16 tests (existing 12 + 4 new pins).
pytest xrspatial/geotiff/tests/test_namespace_no_leak_1708.py xrspatial/geotiff/tests/test_open_geotiff_on_gpu_failure_1615.py xrspatial/geotiff/tests/test_signature_annotations_1654.py -vpasses 30/30.