SDF.data_model.element_set module

class ElementSet(key_func: typing.Callable[T, str], check_func: typing.Callable[T, bool], items: typing.Optional[typing.Iterable[T]] = None)[source]

Bases: typing.Generic[typing.T]

Strictly typed collection that mostly resembles an ordered set, but borrows some behavior of list and dict.

Items must be representable by a str key (like item.name), allowing dict-like access.

Create an empty ElementSet.

Parameters
  • key_func – Function to get a string key from an item (e.g. lambda item: item.name)

  • check_func – Function to check if an item is valid for this ElementSet (e.g. lambda item: hasattr(item, ‘name’) or lambda item: isinstance(item, …)). If it returns True, everything is fine. If it returns False, a default exception is raised. To raise a more specific exception, raise an exception instead of returning False.

add(item: T, as_first: bool = False)None[source]

Add an item to the collection. If as_first, the item is added at the beginning, else at the end.

clear()None[source]

Like dict.clear

copy()SDF.data_model.element_set.ElementSet[T][source]

Return a shallow copy of this collection

items()typing.ItemsView[str, T][source]

Like dict.items

keys()typing.KeysView[str][source]

Like dict.keys

pop(key: typing.Optional[typing.Union[str, int]] = None)T[source]

Like dict.pop if key is str, else like list.pop

remove(item: typing.Union[str, T])None[source]

Remove the item. If key is a string, remove the item specified by key

update(*items: typing.Union[T, typing.Iterable[T]])None[source]

Like set.update

values()typing.ValuesView[T][source]

Like dict.values