Skip to content

Commit

Permalink
return flat list from derived object's formulate() (#629)
Browse files Browse the repository at this point in the history
The StdinDataRedirection command object was returning a list inside a
list, which caused trouble when getting the "str()" of the command.

Example:

    Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from plumbum.cmd import head
    >>> cmd = head['-2'] << "one\ntwo\nthree\nfour"
    >>> print(f"{cmd}")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python310\lib\site-packages\plumbum\commands\base.py", line 66, in __str__
        return " ".join(self.formulate())
    TypeError: sequence item 2: expected str instance, list found
    >>>

Co-authored-by: Jason Singer (js731079) <[email protected]>
  • Loading branch information
nebbish and Jason Singer (js731079) authored Nov 1, 2023
1 parent 8bac666 commit 112b514
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions plumbum/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,8 @@ def _get_encoding(self):
def formulate(self, level=0, args=()):
return [
f"echo {shquote(self.data)}",
"|",
self.cmd.formulate(level + 1, args),
]
"|"
] + self.cmd.formulate(level + 1, args),

@property
def machine(self):
Expand Down

0 comments on commit 112b514

Please sign in to comment.