Skip to content

robot.model.itemlist

ItemList

1
2
3
4
5
ItemList(
    item_class: Type[T],
    common_attrs: dict[str, Any] | None = None,
    items: Iterable[T | DataDict] = (),
)

Bases: MutableSequence[T]

List of items of a certain enforced type.

New items can be created using the :meth:create method and existing items added using the common list methods like :meth:append or :meth:insert. In addition to the common type, items can have certain common and automatically assigned attributes.

Starting from Robot Framework 6.1, items can be added as dictionaries and actual items are generated based on them automatically. If the type has a from_dict class method, it is used, and otherwise dictionary data is passed to the type as keyword arguments.

Source code in src/robot/model/itemlist.py
def __init__(self, item_class: Type[T],
             common_attrs: 'dict[str, Any]|None' = None,
             items: 'Iterable[T|DataDict]' = ()):
    self._item_class = item_class
    self._common_attrs = common_attrs
    self._items: 'list[T]' = []
    if items:
        self.extend(items)

create

create(*args, **kwargs) -> T

Create a new item using the provided arguments.

Source code in src/robot/model/itemlist.py
@copy_signature(item_type)
def create(self, *args, **kwargs) -> T:
    """Create a new item using the provided arguments."""
    return self.append(self._item_class(*args, **kwargs))

to_dicts

to_dicts() -> list[DataDict]

Return list of items converted to dictionaries.

Items are converted to dictionaries using the to_dict method, if they have it, or the built-in vars().

New in Robot Framework 6.1.

Source code in src/robot/model/itemlist.py
def to_dicts(self) -> 'list[DataDict]':
    """Return list of items converted to dictionaries.

    Items are converted to dictionaries using the ``to_dict`` method, if
    they have it, or the built-in ``vars()``.

    New in Robot Framework 6.1.
    """
    if not hasattr(self._item_class, 'to_dict'):
        return [vars(item) for item in self]
    return [item.to_dict() for item in self]    # type: ignore