Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ErisianArchitect opened this issue Oct 9, 2021 · 7 comments

Comments

@ErisianArchitect
Copy link

ErisianArchitect commented Oct 9, 2021

>>> 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__'?```
@Suor
Copy link
Owner

Suor commented Oct 11, 2021

I'll take a look

@Suor
Copy link
Owner

Suor commented Oct 14, 2021

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

@Suor
Copy link
Owner

Suor commented Oct 14, 2021

funcy fails to introspect methods of builtin types.

@Suor Suor changed the title rcurry and similar functions appear to be broken in 3.10. rcurry and similar functions do not work with methods of built-in types Oct 14, 2021
@Suor
Copy link
Owner

Suor commented Nov 7, 2021

The workaround for now is:

has_suffix = rcurry(str.endswith, 2)

@Suor
Copy link
Owner

Suor commented Nov 11, 2021

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

Suor added a commit that referenced this issue Nov 11, 2021
Give up on `str.endswith` and other non-introspectable things for now.
Adjust docs.

Improves on #108.
@Suor
Copy link
Owner

Suor commented Nov 11, 2021

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
Copy link
Owner

Suor commented Mar 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants