Skip to content

GroupSpec signature #20

@d-v-b

Description

@d-v-b

Currently we have

TAttr = TypeVar("TAttr", bound=Mapping[str, Any])
TItem = TypeVar("TItem", bound=Union["GroupSpec", "ArraySpec"])

class GroupSpec(NodeSpecV2, Generic[TAttr, TItem]):
    attributes: TAttr
    members: dict[str, TItem]

This excludes the key space of members from the type domain (the keys can be any strings).

What if we did this instead:

TAttr = TypeVar("TAttr", bound=Mapping[str, Any])
TItem = TypeVar("TItem", bound=Dict[str, Union["GroupSpec", "ArraySpec"]])

class GroupSpec(NodeSpecV2, Generic[TAttr, TItem]):
    attributes: TAttr
    members: TItem

I think this would enable requiring that Zarr groups contain nodes with specific names, e.g.

class MyMembers(TypedDict):
    s0: ArraySpec[ArrayAttrs]
    s1: ArraySpec[ArrayAttrs]

GroupSpec[MyAttributes, MyMembers](...)

But it's not clear to how to make this play nice with pydantic models, since they can't be coerced to Dict[str, blablabla]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions