core.model.datum#
Datum
Module Contents#
Classes#
Atomic declaration of a data value. |
Data#
API#
- core.model.datum.T = None#
- class core.model.datum.Datum#
Atomic declaration of a data value.
- Attributes:
name: The canonical name of the data value. Required. value: For storing a scalar value. children: For storing a collection value. sources: A set recording everywhere the value was seen.
- Notes:
The members of the “sources” attribute is a URI-like string, where the protocol is the plugin and the path is a description of the data source.
- Example:
“file_yaml://…/foo.yaml”
How strict this will be is TBD. For now, it’s loosely defined ad hoc.
- name: polyconf.core.typing_.PrimitiveIndex = None#
- value: polyconf.core.typing_.PrimitiveScalar = None#
- children: set[core.model.datum.Datum] = None#
- sources: set[str] = None#
- property children_names: set[polyconf.core.typing_.PrimitiveIndex]#
Name attributes of all children as a set.
- property as_native_value: polyconf.core.typing_.PrimitiveType#
Native representation of the data value.
- add_child(datum: core.model.datum.Datum, merge: bool = False) None#
Add a child to the collection.
- Args:
datum: The child to add. merge: Whether to merge the existing child with the new one.
- remove_child(datum: core.model.datum.Datum) None#
Remove a child from the collection.
- Args:
datum: The child to remove.
- Note:
- This is more well behaved than:
self.children.discard(datum) (or self.children.remove(datum))
because the native lookup is based on hash, but the desired basis is on name.
- put(name: polyconf.core.typing_.PrimitiveIndex, value: polyconf.core.typing_.PrimitiveScalar = None, source: str | None = None, merge: bool = False) None#
Put a raw value into the collection.
- Args:
name: The name of the value. value: The value to store. source: The source of the value. merge: Whether to merge the existing child with the new one.
- traverse() None#
Traverse the collection.
- get(name: polyconf.core.typing_.PrimitiveIndex, default: core.model.datum.T | None = None) core.model.datum.Datum | core.model.datum.T | None#
Get child datum by name.
Queries self.children for a matching “name” attribute. If not found, it returns a default, which may be specified by the caller.
- Args:
name: The child datum name to retrieve. default: The default value to return if the child is not found. Defaults to None.
- eq_helper() str#
Helper for equality comparison.
- looks_like() Type[str | int | bool | list[Any] | dict[Any, Any]]#
Check if the datum looks like a primitive value.
- classmethod assimilate(name: polyconf.core.typing_.PrimitiveIndex, data: polyconf.core.typing_.PrimitiveType, source: str, parent: Self, merge: bool = False) None#
Assimilate! Naming is hard.
- Args:
name: The name of the value. data: The value to store. source: The source of the value. parent: The parent node. merge: Whether to merge the existing child with the new one.
- classmethod from_dict(data: dict[str, Any], source: str = 'cls-factory') Self#
Create a datum from a dictionary.
- Args:
data: The dictionary to convert to a datum. Keys must be strings. source: The source of the datum.
- Returns:
The datum created from the dictionary.
- classmethod _deserialize(data: polyconf.core.typing_.PrimitiveDict, default_name: str = 'root') Self#
- classmethod deserialize(data: polyconf.core.typing_.PrimitiveDict) Self#
- serialize() polyconf.core.typing_.PrimitiveDict#
Serialize the datum to a dictionary.
- Returns:
The serialized datum.
- __or__(other: Any) core.model.datum.Datum#
Merge this datum with another datum.
This is achieved by serializing the datums to dictionaries, using deep.merge() to merge those dictionaries, then deserializing the merged dictionary back to a datum.
- Args:
other: The datum to merge with.
- Returns:
The merged datum.
- Raises:
NotImplemented: If the other datum is not a datum.
- __ror__(other: core.model.datum.Datum) core.model.datum.Datum#
- __getitem__(item: polyconf.core.typing_.PrimitiveIndex) core.model.datum.Datum | None#
- __contains__(item: core.model.datum.Datum | str) bool#
- __hash__() int#
- __eq__(other: Any) bool#
- __lt__(other: Self) bool#
- __le__(other: Self) bool#
- __gt__(other: Self) bool#
- __ge__(other: Self) bool#