Skip to content

Unexpected regression from standard library: AttributeError is thrown when command is a list rather than a string #5

Description

@klardotsh

While my example below is with Python 3.6 (from Homebrew), I was also able to repro on Python 3.7 (also from Homebrew).

 subprocess.run  » python3
Python 3.6.4 (default, Mar  1 2018, 18:36:50)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

# First, let's look at the standard library's behavior
>>> import subprocess
>>> subprocess.run('clang')
clang: error: no input files
CompletedProcess(args='clang', returncode=1)
>>> subprocess.run(['clang'])
clang: error: no input files
CompletedProcess(args=['clang'], returncode=1)

# And now for the behavior of this library
>>> import run
>>> run.run('clang')
clang
>>> run.run(['clang'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/joshklar/src/subprocess.run/run/__init__.py", line 146, in __new__
    command, stdin, cwd=cwd, env=env, shell=shell)
  File "/Users/joshklar/src/subprocess.run/run/__init__.py", line 121, in create_process
    shlex.split(command),
  File "/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shlex.py", line 305, in split
    return list(lex)
  File "/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shlex.py", line 295, in __next__
    token = self.get_token()
  File "/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shlex.py", line 105, in get_token
    raw = self.read_token()
  File "/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shlex.py", line 136, in read_token
    nextchar = self.instream.read(1)
AttributeError: 'list' object has no attribute 'read'
>

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions