Skip to content

feat: Improved type hinting using zarr-metadata#38

Merged
kylebarron merged 5 commits into
mainfrom
kyle/zarr-metadata-based-types
Jun 22, 2026
Merged

feat: Improved type hinting using zarr-metadata#38
kylebarron merged 5 commits into
mainfrom
kyle/zarr-metadata-based-types

Conversation

@kylebarron

@kylebarron kylebarron commented Jun 22, 2026

Copy link
Copy Markdown
Member

Change list

  • Use explicit types where possible. For example the Zstd codec now has a from_config method that takes something typed as zarr_metadata.v3.codec.zstd.ZstdCodecConfiguration
  • Update ruff formatting rules by forcing zarrista to be known first party
  • Add ruff format check on ci

@kylebarron kylebarron marked this pull request as ready for review June 22, 2026 20:24
@staticmethod
def from_config(config: dict[str, Any]) -> Crc32c:
"""Construct a `crc32c` codec from a configuration mapping, e.g. `{}`."""
def from_config(config: Mapping[str, JSONValue]) -> Crc32c:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Here can we have a typedDict config that is... empty? To force a {} type if anything is provided? Maybe on the rust side we can default to {}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"""The ordered chain of codecs used to encode and decode an array's chunks."""

def __init__(self, metadatas: list[dict[str, Any]]) -> None:
def __init__(self, metadatas: list[MetadataV3]) -> None:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this list should probably be Sequence

Comment on lines -32 to -52
DataTypeName: TypeAlias = Literal[
"bool",
"int8",
"int16",
"int32",
"int64",
"uint8",
"uint16",
"uint32",
"uint64",
"float16",
"float32",
"float64",
"complex64",
"complex128",
"string",
"bytes",
]
"""The Zarr v3 names of the built-in fixed data types.
"""

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ideally upstream zarr-metadata will add its own type union, cc @d-v-b

Comment on lines +24 to +46
DataTypeName: TypeAlias = (
BoolDataTypeName
| Int8DataTypeName
| Int16DataTypeName
| Int32DataTypeName
| Int64DataTypeName
| Uint8DataTypeName
| Uint16DataTypeName
| Uint32DataTypeName
| Uint64DataTypeName
| Float16DataTypeName
| Float32DataTypeName
| Float64DataTypeName
| Complex64DataTypeName
| Complex128DataTypeName
| StringDataTypeName
| BytesDataTypeName
| RawBytesDataTypeName
)
"""The Zarr v3 names of the data types `from_string` can build.

Composed from the per-dtype name literals in `zarr_metadata.v3.data_type`, so
it stays in sync with the spec rather than being hand-maintained here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For now we define our own explicit dtype union, cc @d-v-b

@kylebarron kylebarron enabled auto-merge (squash) June 22, 2026 20:32
@kylebarron kylebarron merged commit ff78948 into main Jun 22, 2026
6 checks passed
@kylebarron kylebarron deleted the kyle/zarr-metadata-based-types branch June 22, 2026 20:33
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.

1 participant