Skip to content

Define parser-specific Store protocols using obspec primitives#859

Open
maxrjones wants to merge 3 commits intozarr-developers:mainfrom
maxrjones:obspec-typing
Open

Define parser-specific Store protocols using obspec primitives#859
maxrjones wants to merge 3 commits intozarr-developers:mainfrom
maxrjones:obspec-typing

Conversation

@maxrjones
Copy link
Copy Markdown
Member

Previously, VirtualiZarr imported ReadableStore from obspec_utils.protocols, which was overly broad relative to the methods used by parsers. This PR updates the parsers to directly define their required protocols using obspec.

As a consequence, obspec is added as a direct dependency (rather than via obspec_utils). I have also bumped the minimum obspec_utils version due to the ParallelStoreBug in v0.7.0 referenced in #858.

  • Closes #xxxx
  • Tests added
  • Tests passing
  • Full type hint coverage
  • Changes are documented in docs/releases.rst
  • New functions/methods are listed in api.rst
  • New functionality has documentation

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.97%. Comparing base (052f7d1) to head (99f2fb3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #859      +/-   ##
==========================================
- Coverage   88.99%   88.97%   -0.03%     
==========================================
  Files          34       34              
  Lines        1945     1959      +14     
==========================================
+ Hits         1731     1743      +12     
- Misses        214      216       +2     
Files with missing lines Coverage Δ
virtualizarr/parsers/dmrpp.py 83.62% <100.00%> (+0.29%) ⬆️
virtualizarr/parsers/hdf/hdf.py 95.65% <100.00%> (+0.12%) ⬆️
virtualizarr/parsers/kerchunk/json.py 100.00% <100.00%> (ø)
virtualizarr/parsers/typing.py 100.00% <100.00%> (ø)
virtualizarr/parsers/zarr.py 97.54% <100.00%> (-1.21%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maxrjones maxrjones requested a review from chuckwondo January 26, 2026 17:13
Copy link
Copy Markdown
Collaborator

@chuckwondo chuckwondo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I have a few minor suggestions that you may wish to consider.

self,
url: str,
registry: ObjectStoreRegistry,
registry: ObjectStoreRegistry["KerchunkJSONParser.Store"],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you put this at the top of the file, you can drop the quotes:

from __future__ import annotations

That's why you didn't need the quotes in hdf.py for HDFParser.Store.

self,
url: str,
registry: ObjectStoreRegistry,
registry: ObjectStoreRegistry["DMRPPParser.Store"],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this at the top of the file in order to drop the quotes:

from __future__ import annotations

# - ParallelStoreReader needs Get + GetRanges + Head
# Each reader's __init__ declares its specific Store protocol for static type checking.
# At runtime, missing methods will raise AttributeError when called.
ReaderFactory = Callable[[Any, str], ReadableFile]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider allowing for more precise typing:

T = TypeVar("T", bound=Get)

ReaderFactory = Callable[[T, str], ReadableFile]

See related comment in hdf.py, where this allows more precise typing of the reader_factory parameter.

self,
group: str | None = None,
drop_variables: Iterable[str] | None = None,
reader_factory: ReaderFactory = ParallelStoreReader,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you incorporate my suggestion in typing.py, you can make this more precise, as follows:

        reader_factory: ReaderFactory[HDFParser.Store] = ParallelStoreReader,

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.

2 participants