Define parser-specific Store protocols using obspec primitives#859
Define parser-specific Store protocols using obspec primitives#859maxrjones wants to merge 3 commits intozarr-developers:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
chuckwondo
left a comment
There was a problem hiding this comment.
Looks good. I have a few minor suggestions that you may wish to consider.
| self, | ||
| url: str, | ||
| registry: ObjectStoreRegistry, | ||
| registry: ObjectStoreRegistry["KerchunkJSONParser.Store"], |
There was a problem hiding this comment.
If you put this at the top of the file, you can drop the quotes:
from __future__ import annotationsThat's why you didn't need the quotes in hdf.py for HDFParser.Store.
| self, | ||
| url: str, | ||
| registry: ObjectStoreRegistry, | ||
| registry: ObjectStoreRegistry["DMRPPParser.Store"], |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
If you incorporate my suggestion in typing.py, you can make this more precise, as follows:
reader_factory: ReaderFactory[HDFParser.Store] = ParallelStoreReader,
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.
docs/releases.rstapi.rst