16 from collections.abc
import MutableSequence
17 from functools
import total_ordering
24 __slots__ = [
'_item_class',
'_common_attrs',
'_items']
26 def __init__(self, item_class, common_attrs=None, items=None):
44 if not isinstance(item, self.
_item_class_item_class):
45 raise TypeError(f
'Only {type_name(self._item_class)} objects '
46 f
'accepted, got {type_name(item)}.')
47 for attr
in common_attrs:
48 setattr(item, attr, common_attrs[attr])
58 def index(self, item, *start_and_end):
59 return self.
_items_items.
index(item, *start_and_end)
70 while index < len(self.
_items_items):
71 yield self.
_items_items[index]
75 if isinstance(index, slice):
77 return self.
_items_items[index]
88 if isinstance(index, slice):
92 self.
_items_items[index] = item
95 del self.
_items_items[index]
98 return item
in self.
_items_items
101 return len(self.
_items_items)
104 return str(list(self))
107 class_name =
type(self).__name__
109 return f
'{class_name}(item_class={item_name}, items={self._items})'
122 while index < len(self.
_items_items):
123 yield self.
_items_items[len(self.
_items_items) - index - 1]
127 return (isinstance(other, ItemList)
129 and self.
_items_items == other._items)
132 return (self.
_item_class_item_class
is other._item_class
136 if not isinstance(other, ItemList):
137 raise TypeError(f
'Cannot order ItemList and {type_name(other)}.')
139 raise TypeError(
'Cannot order incompatible ItemLists.')
140 return self.
_items_items < other._items
143 if not isinstance(other, ItemList):
144 raise TypeError(f
'Cannot add ItemList and {type_name(other)}.')
146 raise TypeError(
'Cannot add incompatible ItemLists.')
150 if isinstance(other, ItemList)
and not self.
_is_compatible_is_compatible(other):
151 raise TypeError(
'Cannot add incompatible ItemLists.')
159 self.
_items_items *= other
def _is_compatible(self, other)
def __imul__(self, other)
def __delitem__(self, index)
def create(self, *args, **kwargs)
def index(self, item, *start_and_end)
def __iadd__(self, other)
def __setitem__(self, index, item)
def _create_new_from(self, items)
def __rmul__(self, other)
def insert(self, index, item)
def __getitem__(self, index)
def _check_type_and_set_attrs(self, *items)
def __init__(self, item_class, common_attrs=None, items=None)
def __contains__(self, item)