EntilZha / PyFunctional

Python library for creating data pipelines with chain functional programming
http://pyfunctional.pedro.ai
MIT License
2.41k stars 132 forks source link

Type Hint Issue with `group_by` Method #206

Open CatBraaain opened 2 months ago

CatBraaain commented 2 months ago

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?