Skip to content

Conversation

@landgrafhomyak
Copy link

Function subprocess.run passes process arguments to subprocess.Popen.__init__ as vararg,

with Popen(*popenargs, **kwargs) as process:

but constructor expects them as single iterable argument,

cpython/Lib/subprocess.py

Lines 813 to 821 in bc26f95

def __init__(self, args, bufsize=-1, executable=None,
stdin=None, stdout=None, stderr=None,
preexec_fn=None, close_fds=True,
shell=False, cwd=None, env=None, universal_newlines=None,
startupinfo=None, creationflags=0,
restore_signals=True, start_new_session=False,
pass_fds=(), *, user=None, group=None, extra_groups=None,
encoding=None, errors=None, text=None, umask=-1, pipesize=-1,
process_group=None):

so path to executable gets into args, first process argument gets into bufsize, second to executable and so on.

Example programm (tested on 3.8, but seems this part of code still not fixed):

from subprocess import run
run("git", "status")

Error:

Traceback (most recent call last):
  File "<test programm>", line 2, in <module>
    run("git", "status")
  File "stdlib/subprocess.py", line 493, in run
    with Popen(*popenargs, **kwargs) as process:
  File "stdlib/subprocess.py", line 757, in __init__
    raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

This PR provides fix of this error, but subprocess.run definition should be reviewed because in source, stubs and docs it has different signature (vararg/position of asterisc).

@landgrafhomyak landgrafhomyak requested a review from gpshead as a code owner March 23, 2025 02:58
@ghost
Copy link

ghost commented Mar 23, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Mar 23, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Mar 23, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@gpshead
Copy link
Member

gpshead commented Mar 23, 2025

args as passed to both subprocess.run and the subprocess.Popen constructor is and always has been a sequence (list or tuple).

Please do not open pull requests without filing an issue first. Regardless, we'd also just be closing the issue as this isn't a bug.

@gpshead gpshead closed this Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants