kachayev / fn.py

Functional programming in Python: implementation of missing features to enjoy FP
Other
3.35k stars 203 forks source link

curried decorator does not work with type annotations #97

Open phelps-sg opened 1 year ago

phelps-sg commented 1 year ago
from fn.func import curried
@curried
def sum5(a, b, c, d, e):
    return a + b + c + d +e
sum5(1)(2)(3)(4)(5)
Out[6]: 15
@curried
def sum5(a: int, b: int, c: int, d: int, e: int):
    return a + b + c + d +e
sum5(1)(2)(3)(4)(5)
Traceback (most recent call last):
  File "/home/sphelps/mambaforge/envs/symbiotica-fund/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3505, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-8-e80b0556d52b>", line 1, in <module>
    sum5(1)(2)(3)(4)(5)
  File "/home/sphelps/mambaforge/envs/symbiotica-fund/lib/python3.10/site-packages/fn/func.py", line 78, in _curried
    spec = getargspec(f)
  File "/home/sphelps/mambaforge/envs/symbiotica-fund/lib/python3.10/inspect.py", line 1237, in getargspec
    raise ValueError("Function has keyword-only parameters or annotations"
ValueError: Function has keyword-only parameters or annotations, use inspect.signature() API which can support them