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

cannot cast to string a StdinDataRedirection-bound LocalCommand #398

Open
jesteria opened this issue Aug 1, 2018 · 0 comments
Open

cannot cast to string a StdinDataRedirection-bound LocalCommand #398

jesteria opened this issue Aug 1, 2018 · 0 comments

Comments

@jesteria
Copy link
Contributor

jesteria commented Aug 1, 2018

Having directed string input into the standard input of a LocalCommand (via << i.e. __lshift__), I am unable to cast the resulting StdinDataRedirection object to string. Attempting to do so raises an uncaught exception.

$ ipython
Python 3.6.3 (default, Dec 20 2017, 11:51:43) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import plumbum

In [2]: plumbum.__version__
Out[2]: (1, 6, 4)

In [3]: cat = plumbum.local['cat']

In [4]: stdin_bound_cat = cat << 'hello world'

In [5]: str(stdin_bound_cat)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-15af60a0e450> in <module>()
----> 1 str(stdin_bound_cat)

~/.pyenv/versions/3.6.3/envs/test/lib/python3.6/site-packages/plumbum/commands/base.py in __str__(self)
     49
     50     def __str__(self):
---> 51         return " ".join(self.formulate())
     52
     53     def __or__(self, other):

TypeError: sequence item 2: expected str instance, list found

Underlying this issue is that the formulate() method for this object returns a list which itself contains both strings and lists:

In [6]: stdin_bound_cat.formulate()
Out[6]: ["echo 'hello world'", '|', ['/bin/cat']]

which result cannot simply be joined by a string, as its __str__ attempts to do.

Needless to say, this issue prevents passing such objects to print(), and minorly complicates introspection.

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

1 participant