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

functools.partial as argument to _out fails #160

Closed
ianw opened this issue Oct 22, 2013 · 2 comments
Closed

functools.partial as argument to _out fails #160

ianw opened this issue Oct 22, 2013 · 2 comments

Comments

@ianw
Copy link

ianw commented Oct 22, 2013

Something like

import functools
import sh

def _log_line(foo, line, stdin, process):
    print "%s : %s" % (foo, line)

log_line = functools.partial(_log_line, "hello")

a = sh.ls("-l", "/var/tmp", _out=log_line)

fails with

Traceback (most recent call last):
  File "/tmp/test.py", line 9, in <module>
    a = sh.ls("-l", "/var/tmp", _out=log_line)
  File "/opt/data/env/lib/python2.7/site-packages/sh.py", line 769, in __call__
    return RunningCommand(cmd, call_args, stdin, stdout, stderr)
  File "/opt/data/env/lib/python2.7/site-packages/sh.py", line 327, in __init__
    self.call_args, pipe=pipe)
  File "/opt/data/env/lib/python2.7/site-packages/sh.py", line 961, in __init__
    save_data=save_stdout)
  File "/opt/data/env/lib/python2.7/site-packages/sh.py", line 1360, in __init__
    num_args = len(inspect.getargspec(handler.__call__).args)
  File "/usr/lib64/python2.7/inspect.py", line 815, in getargspec
    raise TypeError('{!r} is not a Python function'.format(func))
TypeError: <method-wrapper '__call__' of functools.partial object at 0x7f31bada11b0> is not a Python function

It seems to be a semi-common problem with inspect and functools. There are several pointers to the alternative implementation

https://bitbucket.org/macfreek/sphinx/src/2db7eac2830b/sphinx/util/inspect.py#cl-24

when googling for the error.

@amoffat
Copy link
Owner

amoffat commented Oct 24, 2013

Thanks for reporting this Ian. It's a result of sh trying to be too clever...I will take a look at this soon.

amoffat pushed a commit that referenced this issue Dec 30, 2014
@amoffat
Copy link
Owner

amoffat commented Dec 30, 2014

fixed on release-1.10 branch

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

No branches or pull requests

2 participants