git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problem with curring in python


On 22/10/19 12:02, Terry Reedy wrote:
> On 10/22/2019 4:58 AM, Antoon Pardon wrote:
>> Using python 3.5
>>
>> I have been experimenting with curried functions. A bit like in Haskell.
>> So I can write the following function:
>>
>> def sum4(a, b, c, d):
>> ???? return a + b + c + d
>>
>> summing = curry(sum4)
>>
>> print summing(1)(2)(3)(4) # this prints 10.
>>
>> The problem is I need the signature of the original function in order to
>> know when to finally call the function and return the actual result.
>> However buildin functions don't have a
>
> I believe most do.

Well I may have jumped to my conclusion, but those in operator don't seem
to have a signature.

>>> inspect.signature(operator.mul)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/inspect.py", line 2988, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
  File "/usr/lib/python3.5/inspect.py", line 2738, in from_callable
    follow_wrapper_chains=follow_wrapped)
  File "/usr/lib/python3.5/inspect.py", line 2231, in _signature_from_callable
    skip_bound_arg=skip_bound_arg)
  File "/usr/lib/python3.5/inspect.py", line 2061, in _signature_from_builtin
    raise ValueError("no signature found for builtin {!r}".format(func))
ValueError: no signature found for builtin <built-in function mul>

-- 
Antoon.