dataspecs.core.specs module#
- class ID(*segments: str | PathLike[str])[source]#
Bases:
PurePosixPathIdentifier (ID) for data specs.
It is based on
PurePosixPath, however, the differences are an ID must start with the root (/) and thematchmethod full-matches a regular expression.- Parameters:
*segments (str | PathLike[str]) – Path segments to create an ID.
- Raises:
ValueError – Raised if it does not start with the root.
- Return type:
Self
- property children: Self#
Return the regular expression that matches the child IDs.
- property descendants: Self#
Return the regular expression that matches the descendant IDs.
- ROOT = ID('/')#
Root ID.
- class Spec(id: ~dataspecs.core.specs.ID, tags: tuple[~dataspecs.core.typing.TagBase, ...], type: ~typing.Any, data: ~dataspecs.core.typing.TAny, meta: tuple[~typing.Any, ...] = <factory>)[source]#
Bases:
Generic[TAny]Data specification (data spec).
- Parameters:
- type: Any#
Type hint for the data of the data spec.
- data: TAny#
Default or final data of the data spec.
- meta: tuple[Any, ...]#
Other metadata of the data spec.
- class Specs(initlist=None)[source]#
Bases:
UserList[TSpec]Data specifications (data specs).
- property first: TSpec | None#
Return the first data spec if it exists (
Noneotherwise).
- property last: TSpec | None#
Return the last data spec if it exists (
Noneotherwise).
- property unique: TSpec | None#
Return the data spec if it is unique (
Noneotherwise).
- replace(old: TSpec, new: TSpec, /) Self[source]#
Return data specs with old data spec replaced by new one.
- Parameters:
old (TSpec)
new (TSpec)
- Return type:
Self
- __getitem__(index: None, /) Self[source]#
- __getitem__(index: TagBase, /) Self
- __getitem__(index: type[Any], /) Self
- __getitem__(index: str | PathLike[str], /) Self
- __getitem__(index: slice, /) Self
- __getitem__(index: SupportsIndex, /) TSpec
Select data specs with given index.
In addition to a normal index (i.e. an object that has
__index__method), it also accepts the following extended index for the advanced selection: (1) a tag to select data specs that contain it, (2) a tag type to select data specs that contain its tags, (3) an any type to select data specs that contain it, (4) a string path to select data specs that match it, or (5)Noneto return all data specs (shallow copy).- Parameters:
index – Normal or extended index for the selection of the data specs.
- Returns:
Selected data specs with given index.