napari.utils.events.TypedMutableSequence#

class napari.utils.events.TypedMutableSequence(data: Iterable[_T] = (), *, basetype: Type[_T] | Sequence[Type[_T]] = (), lookup: Dict[Type[_L], Callable[[_T], _T | _L]] | None = None)[source]#

Bases: MutableSequence[_T]

List mixin that enforces item type, and enables custom indexing.

Parameters:
  • data (iterable, optional) – Elements to initialize the list with.

  • basetype (type or sequence of types, optional) – Type of the elements in the list. If a basetype (or multiple) is provided, then a TypeError will be raised when attempting to add an item to this sequence if it is not an instance of one of the types in basetype.

  • lookup (dict of Type[L] : function(object) -> L) – Mapping between a type, and a function that converts items in the list to that type. This is used for custom indexing. For example, if a lookup of {str: lambda x: x.name} is provided, then you can index into the list using list['frank'] and it will search for an object whos attribute .name equals 'frank'.

Methods

append(value)

S.append(value) -- append value to the end of the sequence

clear()

copy()

Return a shallow copy of the list.

count(value)

extend(values)

S.extend(iterable) -- extend sequence by appending elements from the iterable

index(value[, start, stop])

Return first index of value.

insert(index, value)

S.insert(index, value) -- insert value before index

pop([index])

Raise IndexError if list is empty or index is out of range.

remove(value)

S.remove(value) -- remove first occurrence of value.

reverse()

S.reverse() -- reverse IN PLACE

Details

append(value)#

S.append(value) – append value to the end of the sequence

clear() None -- remove all items from S#
copy() Self[source]#

Return a shallow copy of the list.

count(value) integer -- return number of occurrences of value#
extend(values)#

S.extend(iterable) – extend sequence by appending elements from the iterable

index(value: _L, start: int = 0, stop: int | None = None) int[source]#

Return first index of value.

Parameters:
  • value (Any) – A value to lookup. If type(value) is in the lookups functions provided for this class, then values in the list will be searched using the corresponding lookup converter function.

  • start (int, optional) – The starting index to search, by default 0

  • stop (int, optional) – The ending index to search, by default None

Returns:

The index of the value

Return type:

int

Raises:

ValueError – If the value is not present

insert(index: int, value: _T)[source]#

S.insert(index, value) – insert value before index

pop([index]) item -- remove and return item at index (default last).#

Raise IndexError if list is empty or index is out of range.

remove(value)#

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

reverse()#

S.reverse() – reverse IN PLACE