PyFunctional icon indicating copy to clipboard operation
PyFunctional copied to clipboard

Type Hint Issue with `group_by` Method

Open CatBraaain opened this issue 5 months ago • 0 comments

I tried this code

pip install git+https://github.com/EntilZha/PyFunctional.git
from functional import seq
seq((1, 2), (2, 3)).group_by(lambda e: e[0]).filter(lambda e: len(e[1]) > 0)

mypy says

Argument 1 to "len" has incompatible type "Sequence[LogEntry]"; expected "Sized"

Imo, type hint of .group_by() is wrong and should be like as

     def group_by(
         self, func: Callable[[_T_co], _T]
-    ) -> Sequence[tuple[_T, Sequence[_T_co]]]:
+    ) -> Sequence[tuple[_T, list[_T_co]]]:

You can see the code of .group_by() method here. https://github.com/EntilZha/PyFunctional/blob/d1b64791da61954a48160eded823ccabb00f0566/functional/pipeline.py#L1075-L1077

But I'm not sure. Could anyone check this, please?

CatBraaain avatar Sep 23 '24 13:09 CatBraaain