Base collections
base_collections
¶
Generic dict- and list-like pydantic RootModel base classes.
BaseDict
¶
Bases: RootModel[dict[str, T]]
__getitem__
¶
__getitem__(key: str) -> T
Get an item in the dictionary with the specified key.
__setitem__
¶
__setitem__(key: str, value: T) -> None
Set the value of a single key-value pair.
Source code in src/stochas/base_collections.py
__iter__
¶
__contains__
¶
__reversed__
¶
pop
¶
pop(key: str, *default: T) -> T
Removes the specified key and returns the corresponding value. Raises KeyError if the key is not found and no default is given.
Source code in src/stochas/base_collections.py
popitem
¶
clear
¶
setdefault
¶
setdefault(key: str, default: T) -> T
Returns the value for key if it exists, otherwise inserts default and returns it.
keys
¶
values
¶
items
¶
update
¶
Add a new dictionary key value pair. The key cannot already exist in the dictionary.
Source code in src/stochas/base_collections.py
update_many
¶
update_many(values: Iterable[T]) -> None
Add many new dictionary key value pair. The keys cannot already exist in the dictionary.
force_update
¶
force_update(value: T, warn: bool = True) -> None
Forces a key-value pair into the dictionary. Overwrites existing key if it exists.
Source code in src/stochas/base_collections.py
| Python | |
|---|---|
force_update_many
¶
Forces adding many new dictionary key value pair. Overwrites existing keys if they exist.
Source code in src/stochas/base_collections.py
BaseList
¶
__contains__
¶
__getitem__
¶
append
¶
__add__
¶
Returns a new list with the contents of both lists concatenated.
Source code in src/stochas/base_collections.py
__iadd__
¶
Extends the list in place with the contents of another list.
remove
¶
clear
¶
index
¶
Return the index of the first occurrence of a value.
reverse
¶
sort
¶
sort(
*,
key: Callable[[T], SupportsRichComparison]
| None = None,
reverse: bool = False,
) -> None
Sort the list in place.
HasUnitsCollection
¶
Mixin for BaseDict subclasses whose items carry unit: UnitDescriptor | str | None. Provides a single shared update_unit_system implementation so DistributionDict, DesignValueDict, and NamedValueDict do not each repeat the same loop.
update_unit_system
¶
update_unit_system(us: UnitSystem) -> None
Re-resolves UnitDescriptor conversion factors for every item whose unit field is a UnitDescriptor (plain-string labels are left untouched).