Fixed OrderedQueryable imports

This commit is contained in:
Sven Heidemann 2023-04-04 13:55:50 +02:00
parent 8c012e5902
commit 083e1ce4a1
3 changed files with 13 additions and 4 deletions

View File

@ -1,4 +1,5 @@
from collections.abc import Callable from collections.abc import Callable
from typing import Self
from cpl_query.base.ordered_queryable_abc import OrderedQueryableABC from cpl_query.base.ordered_queryable_abc import OrderedQueryableABC
from cpl_query.exceptions import ArgumentNoneException, ExceptionArgument from cpl_query.exceptions import ArgumentNoneException, ExceptionArgument
@ -6,12 +7,12 @@ from cpl_query.iterable.iterable import Iterable
class OrderedQueryable(OrderedQueryableABC): class OrderedQueryable(OrderedQueryableABC):
r"""Implementation of :class: `cpl_query.extension.Iterable` `cpl_query.extension.OrderedIterableABC`""" r"""Implementation of :class: `cpl_query.base.ordered_queryable_abc.OrderedQueryableABC`"""
def __init__(self, _t: type, _values: Iterable = None, _func: Callable = None): def __init__(self, _t: type, _values: Iterable = None, _func: Callable = None):
OrderedQueryableABC.__init__(self, _t, _values, _func) OrderedQueryableABC.__init__(self, _t, _values, _func)
def then_by(self: OrderedQueryableABC, _func: Callable) -> OrderedQueryableABC: def then_by(self, _func: Callable) -> Self:
if self is None: if self is None:
raise ArgumentNoneException(ExceptionArgument.list) raise ArgumentNoneException(ExceptionArgument.list)
@ -22,7 +23,7 @@ class OrderedQueryable(OrderedQueryableABC):
return OrderedQueryable(self.type, sorted(self, key=lambda *args: [f(*args) for f in self._funcs]), _func) return OrderedQueryable(self.type, sorted(self, key=lambda *args: [f(*args) for f in self._funcs]), _func)
def then_by_descending(self: OrderedQueryableABC, _func: Callable) -> OrderedQueryableABC: def then_by_descending(self, _func: Callable) -> Self:
if self is None: if self is None:
raise ArgumentNoneException(ExceptionArgument.list) raise ArgumentNoneException(ExceptionArgument.list)

View File

@ -1,6 +1,12 @@
from __future__ import annotations
from typing import Optional, Callable, Union, Iterable, Self from typing import Optional, Callable, Union, Iterable, Self
from typing import TYPE_CHECKING
from cpl_query._helper import is_number from cpl_query._helper import is_number
if TYPE_CHECKING:
from cpl_query.base.ordered_queryable_abc import OrderedQueryableABC
from cpl_query.base.sequence import Sequence from cpl_query.base.sequence import Sequence
from cpl_query.exceptions import ( from cpl_query.exceptions import (
InvalidTypeException, InvalidTypeException,
@ -315,7 +321,7 @@ class QueryableABC(Sequence):
return _func(min(self, key=_func)) return _func(min(self, key=_func))
def order_by(self, _func: Callable = None) -> "OrderedQueryableABC": def order_by(self, _func: Callable = None) -> OrderedQueryableABC:
r"""Sorts elements by function in ascending order r"""Sorts elements by function in ascending order
Parameter Parameter

View File

@ -251,6 +251,8 @@ class IterableQueryTestCase(unittest.TestCase):
self.assertEqual(res, s_res) self.assertEqual(res, s_res)
def test_then_by_descending(self): def test_then_by_descending(self):
x = List(int, List.range(1, 10)).order_by(lambda x: x).th
res = ( res = (
self._tests.order_by_descending(lambda user: user.address.street) self._tests.order_by_descending(lambda user: user.address.street)
.then_by_descending(lambda user: user.address.nr) .then_by_descending(lambda user: user.address.nr)