Skip to content

Commit 6e1528a

Browse files
committed
Fix typing issues with sorted
1 parent 3fe1ac3 commit 6e1528a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

expression/collections/frozenlist.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@
3737
overload,
3838
)
3939

40-
from expression.core import Case, Nothing, Option, Some, pipe
40+
from expression.core import Case, Nothing, Option, Some, SupportsLessThan, pipe
4141

4242
from . import seq
4343

4444
TSource = TypeVar("TSource")
45+
TSourceSortable = TypeVar("TSourceSortable", bound=SupportsLessThan)
4546
TSourceIn = TypeVar("TSourceIn", contravariant=True)
4647
TResult = TypeVar("TResult")
4748
TResultOut = TypeVar("TResultOut", covariant=True)
4849
TState = TypeVar("TState")
50+
4951
T1 = TypeVar("T1")
5052
T2 = TypeVar("T2")
5153
T3 = TypeVar("T3")
@@ -356,7 +358,7 @@ def tail(self) -> FrozenList[TSource]:
356358
_, *tail = self.value
357359
return FrozenList(tail)
358360

359-
def sort(self, reverse: bool = False) -> FrozenList[TSource]:
361+
def sort(self: FrozenList[TSourceSortable], reverse: bool = False) -> FrozenList[TSourceSortable]:
360362
"""Sort list directly.
361363
362364
Returns a new sorted collection.
@@ -779,7 +781,7 @@ def _skip_last(source: FrozenList[TSource]) -> FrozenList[TSource]:
779781
return _skip_last
780782

781783

782-
def sort(reverse=False) -> Callable[[FrozenList[TSource]], FrozenList[TSource]]:
784+
def sort(reverse: bool = False) -> Callable[[FrozenList[TSourceSortable]], FrozenList[TSourceSortable]]:
783785
"""Returns a new sorted collection
784786
785787
Args:
@@ -789,7 +791,7 @@ def sort(reverse=False) -> Callable[[FrozenList[TSource]], FrozenList[TSource]]:
789791
Partially applied sort function.
790792
"""
791793

792-
def _sort(source: FrozenList[TSource]) -> FrozenList[TSource]:
794+
def _sort(source: FrozenList[TSourceSortable]) -> FrozenList[TSourceSortable]:
793795
"""Returns a new sorted collection
794796
795797
Args:
@@ -803,7 +805,9 @@ def _sort(source: FrozenList[TSource]) -> FrozenList[TSource]:
803805
return _sort
804806

805807

806-
def sort_with(func: Callable[[TSource], Any], reverse=False) -> Callable[[FrozenList[TSource]], FrozenList[TSource]]:
808+
def sort_with(
809+
func: Callable[[TSource], Any], reverse: bool = False
810+
) -> Callable[[FrozenList[TSource]], FrozenList[TSource]]:
807811
"""Returns a new collection sorted using "func" key function.
808812
809813
Args:

0 commit comments

Comments
 (0)