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

Fix StdinDataRedirection's formulate() method #629

Merged

Conversation

nebbish
Copy link
Contributor

@nebbish nebbish commented Jan 11, 2023

return flat list from derived object's formulate()

The StdinDataRedirection command object was returning a list inside a list, which caused trouble when getting the "str()" of the command.

Simple example to demonstrate the problem:

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
>>>

This addresses open issue #398

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
    >>>
Comment on lines +539 to +540
"|"
] + self.cmd.formulate(level + 1, args),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"|"
] + self.cmd.formulate(level + 1, args),
"|",
*self.cmd.formulate(level + 1, args),
]

@henryiii henryiii merged commit 112b514 into tomerfiliba:master Nov 1, 2023
henryiii added a commit that referenced this pull request Nov 1, 2023
Signed-off-by: Henry Schreiner <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants