Skip to content

Commit 8937241

Browse files
committed
Fix some type errors
1 parent 03090f3 commit 8937241

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pyfluent_iterables/fluent.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Dict,
2222
Union,
2323
Literal,
24+
cast,
2425
overload,
2526
)
2627

@@ -59,7 +60,7 @@ def fluent_dict(
5960
otherwise the result will wrap a new dictionary object.
6061
"""
6162
if not kwargs and isinstance(mapping_or_iterable, Mapping):
62-
return FluentMapping(mapping_or_iterable)
63+
return FluentMapping(cast(Mapping[K, V], mapping_or_iterable))
6364
if mapping_or_iterable is None:
6465
return FluentMapping[str, Any](kwargs) # type: ignore[return-value]
6566
return FluentMapping(dict(mapping_or_iterable, **kwargs))
@@ -191,7 +192,7 @@ def accumulate(self, function: Callable[[Union[T, R], T], R], initial: Optional[
191192
######
192193
# Stateful intermediate operations
193194
######
194-
def sort(self, key: Callable[[T], Any] = None, reverse: bool = False) -> "FluentIterable[T]":
195+
def sort(self, key: Optional[Callable[[T], Any]] = None, reverse: bool = False) -> "FluentIterable[T]":
195196
"""
196197
Returns a FluentIterable containing elements from this iterable sorted by the output of the `key` function applied to all elements of this iterable
197198
(identity is used if `key` is None). Returns elements in the reverse order if `reverse` is True.
@@ -204,7 +205,7 @@ def distinct(self) -> "FluentIterable[T]":
204205
# Dictionary is guaranteed to preserve insertion order since 3.7
205206
return FluentIterableWrapper(dict.fromkeys(self._iterable()))
206207

207-
def group_by(self, key: Callable[[T], S] = None) -> "FluentMapping[S, List[T]]":
208+
def group_by(self, key: Optional[Callable[[T], S]] = None) -> "FluentMapping[S, List[T]]":
208209
"""
209210
Groups elements of this iterable by values of the `key` function applied to each element (the element itself is used if `key` is not provided).
210211
Returns a FluentMapping where the key corresponds to the result of the `key` function and value corresponds to a list of all elements which mapped to the respective key.
@@ -376,21 +377,21 @@ def __len__(self) -> int:
376377

377378
def sum(self):
378379
"""Returns the sum of elements in this iterable with the sum() built-in function"""
379-
return sum(self._iterable())
380+
return sum(self._iterable()) # type: ignore
380381

381382
def min(self, key: Optional[Callable[[T], Any]] = None, default: Optional[T] = None):
382383
"""
383384
Return the smallest item in this iterable. The arguments have identical meaning to the min() built-in function:
384385
`key` specifies a function used to extract a comparison key, `default` specifies result value if this iterable is empty.
385386
"""
386-
return min(self._iterable(), key=key, default=default)
387+
return min(self._iterable(), key=key, default=default) # type: ignore
387388

388389
def max(self, key: Optional[Callable[[T], Any]] = None, default: Optional[T] = None):
389390
"""
390391
Return the smallest item in this iterable. The arguments have identical meaning to the min() built-in function:
391392
`key` specifies a function used to extract a comparison key, `default` specifies result value if this iterable is empty.
392393
"""
393-
return max(self._iterable(), key=key, default=default)
394+
return max(self._iterable(), key=key, default=default) # type: ignore
394395

395396
def reduce(
396397
self,

0 commit comments

Comments
 (0)