funcy icon indicating copy to clipboard operation
funcy copied to clipboard

rcurry and similar functions do not work with methods of built-in types

Open ErisianArchitect opened this issue 4 years ago • 7 comments

>>> has_suffix = rcurry(str.endswith)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\funcy\funcs.py", line 57, in rcurry
    n = get_spec(func).max_n
  File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\funcy\_inspect.py", line 108, in get_spec
    mod = func.__module__
AttributeError: 'method_descriptor' object has no attribute '__module__'. Did you mean: '__reduce__'?```

ErisianArchitect avatar Oct 09 '21 02:10 ErisianArchitect

I'll take a look

Suor avatar Oct 11 '21 05:10 Suor

Ok, rcurry() and friends behave the same in Python 3.8 and 3.10. And it doesn't work with str.endswith indeed.

Suor avatar Oct 14 '21 06:10 Suor

funcy fails to introspect methods of builtin types.

Suor avatar Oct 14 '21 07:10 Suor

The workaround for now is:

has_suffix = rcurry(str.endswith, 2)

Suor avatar Nov 07 '21 12:11 Suor

Also, str.endswith actually have 4 params, so your example won't work anyway.

Suor avatar Nov 11 '21 09:11 Suor

Updated docs and readme to recommend specifying n. The issue itself is frozen for now, since I don't see much value in doing proper introspection here.

Suor avatar Nov 11 '21 09:11 Suor

Note that as a last resort funcy goes to inspect.signature(), which might work or not for the same thing depending on Python version.

Suor avatar Mar 11 '23 06:03 Suor