typespecs.mapping module#

typespecs.mapping.fill(mappings: Iterable[Mapping[TKey, TValue]], filler: Mapping[Hashable, Any] | Any, /) → list[dict[Hashable, Any]][source]#

Fill missing keys in the given mappings.

Parameters:
  • mappings – Iterable of mappings to fill.

  • filler – Value(s) to fill missing keys with.

Returns:

List of filled dictionaries.

typespecs.mapping.group(mappings: Iterable[TMapping], key: Hashable | Callable[[TMapping], Hashable], /) → list[list[TMapping]][source]#

Group the given mappings by the given key.

Parameters:
  • mappings – Iterable of mappings to group.

  • key – Key or function to group by.

Returns:

List of groups of mappings.

typespecs.mapping.merge(mappings: Iterable[Mapping[TKey, TValue]], resolver: Mapping[Hashable, Callable[[Any, Any], Any] | Literal['override', 'update']] | Callable[[Any, Any], Any] | Literal['override', 'update'], /) → dict[TKey, TValue][source]#

Merge the given mappings into a single dictionary.

Parameters:
  • mappings – Iterable of mappings to merge.

  • resolver – Function(s) to resolve conflicts.

Returns:

Merged dictionary.

typespecs.mapping.pop(mappings: Iterable[MutableMapping[TKey, TValue]], key: TKey, /) → list[TValue][source]#

Remove a key from the given mappings in-place.

Parameters:
  • mappings – Iterable of mappings to remove the key from.

  • key – Key to be removed.

Returns:

List of removed values.

typespecs.mapping.sort(mappings: Iterable[TMapping], key: Hashable | Callable[[TMapping], SortKey], /, *, reverse: bool = False) → list[TMapping][source]#

Sort the given mappings.

Parameters:
  • mappings – Iterable of mappings to sort.

  • key – Key or function to sort by.

  • reverse – Whether to sort in reverse order.

Returns:

List of sorted mappings.