Minor fixes to cpl query
This commit is contained in:
parent
b02aebef35
commit
2e0a8bb1ff
@ -3,8 +3,8 @@
|
|||||||
"Name": "cpl-discord",
|
"Name": "cpl-discord",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2022",
|
"Major": "2022",
|
||||||
"Minor": "10",
|
"Minor": "12",
|
||||||
"Micro": "0.post6"
|
"Micro": "0"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
@ -21,6 +21,10 @@ class SequenceABC(ABC):
|
|||||||
self._type = t
|
self._type = t
|
||||||
self._set_values(values)
|
self._set_values(values)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __class_getitem__(cls, _t: type):
|
||||||
|
return _t
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._values)
|
return len(self._values)
|
||||||
|
|
||||||
@ -71,6 +75,15 @@ class SequenceABC(ABC):
|
|||||||
"""
|
"""
|
||||||
return [x for x in self]
|
return [x for x in self]
|
||||||
|
|
||||||
|
def copy(self) -> 'SequenceABC':
|
||||||
|
r"""Creates a copy of sequence
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
SequenceABC
|
||||||
|
"""
|
||||||
|
return type(self)(self._type, self.to_list())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def empty(cls) -> 'SequenceABC':
|
def empty(cls) -> 'SequenceABC':
|
||||||
r"""Returns an empty sequence
|
r"""Returns an empty sequence
|
||||||
@ -81,6 +94,23 @@ class SequenceABC(ABC):
|
|||||||
"""
|
"""
|
||||||
return cls()
|
return cls()
|
||||||
|
|
||||||
|
def index(self, _object: object) -> int:
|
||||||
|
r"""Returns the index of given element
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Index of object
|
||||||
|
|
||||||
|
Raises
|
||||||
|
-------
|
||||||
|
IndexError if object not in sequence
|
||||||
|
"""
|
||||||
|
for i, o in enumerate(self):
|
||||||
|
if o == _object:
|
||||||
|
return i
|
||||||
|
|
||||||
|
raise IndexError
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def range(cls, start: int, length: int) -> 'SequenceABC':
|
def range(cls, start: int, length: int) -> 'SequenceABC':
|
||||||
return cls(int, list(range(start, length)))
|
return cls(int, list(range(start, length)))
|
||||||
|
@ -56,6 +56,20 @@ class IterableABC(QueryableABC):
|
|||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def remove(self, _object: object):
|
||||||
|
r"""Removes element from list
|
||||||
|
Parameter
|
||||||
|
---------
|
||||||
|
_object: :class:`object`
|
||||||
|
value
|
||||||
|
"""
|
||||||
|
if _object not in self:
|
||||||
|
raise ValueError
|
||||||
|
|
||||||
|
values = [*self._values]
|
||||||
|
values.remove(_object)
|
||||||
|
self._set_values(values)
|
||||||
|
|
||||||
def to_enumerable(self) -> 'EnumerableABC':
|
def to_enumerable(self) -> 'EnumerableABC':
|
||||||
r"""Converts :class: `cpl_query.iterable.iterable_abc.IterableABC` to :class: `cpl_query.enumerable.enumerable_abc.EnumerableABC`
|
r"""Converts :class: `cpl_query.iterable.iterable_abc.IterableABC` to :class: `cpl_query.enumerable.enumerable_abc.EnumerableABC`
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ class IterableQueryTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(skipped.to_list(), self._tests[:-5])
|
self.assertEqual(skipped.to_list(), self._tests[:-5])
|
||||||
self.assertEqual(skipped.last(), self._tests[:-5][len(self._tests[:-5]) - 1])
|
self.assertEqual(skipped.last(), self._tests[:-5][len(self._tests[:-5]) - 1])
|
||||||
|
|
||||||
def test_sum(self):
|
def test_sum(self) -> List['int']:
|
||||||
res = self._tests.sum(lambda u: u.address.nr)
|
res = self._tests.sum(lambda u: u.address.nr)
|
||||||
|
|
||||||
s_res = 0
|
s_res = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user