diff options
author | Subhendu Ghosh <subho.prp@gmail.com> | 2017-02-25 14:59:05 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2017-02-25 14:59:05 (GMT) |
commit | ae160bba2030a7b6c86f6c7aeaf2f9d3fdb627b7 (patch) | |
tree | 82df8ee0582f8a14dba8154fdd18b5383ac21f62 /Lib | |
parent | 21024f06622c4c55b666adb130797a4ee205d005 (diff) | |
download | cpython-ae160bba2030a7b6c86f6c7aeaf2f9d3fdb627b7.zip cpython-ae160bba2030a7b6c86f6c7aeaf2f9d3fdb627b7.tar.gz cpython-ae160bba2030a7b6c86f6c7aeaf2f9d3fdb627b7.tar.bz2 |
bpo-26128: Added __init__to subprocess.STARTUPINFO (#171)
The Windows-specific subprocess.STARTUPINFO class now accepts
keyword-only arguments to its constructor to set the various
data attributes.
Patch by Subhendu Ghosh.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/subprocess.py | 12 | ||||
-rw-r--r-- | Lib/test/test_subprocess.py | 16 |
2 files changed, 23 insertions, 5 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 67b9c9f..dffcda3 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -127,11 +127,13 @@ if _mswindows: import msvcrt import _winapi class STARTUPINFO: - dwFlags = 0 - hStdInput = None - hStdOutput = None - hStdError = None - wShowWindow = 0 + def __init__(self, *, dwFlags=0, hStdInput=None, hStdOutput=None, + hStdError=None, wShowWindow=0): + self.dwFlags = dwFlags + self.hStdInput = hStdInput + self.hStdOutput = hStdOutput + self.hStdError = hStdError + self.wShowWindow = wShowWindow else: import _posixsubprocess import select diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 82e0b87..812e7bf 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2550,6 +2550,22 @@ class Win32ProcessTestCase(BaseTestCase): subprocess.call([sys.executable, "-c", "import sys; sys.exit(0)"], startupinfo=startupinfo) + def test_startupinfo_keywords(self): + # startupinfo argument + # We use hardcoded constants, because we do not want to + # depend on win32all. + STARTF_USERSHOWWINDOW = 1 + SW_MAXIMIZE = 3 + startupinfo = subprocess.STARTUPINFO( + dwFlags=STARTF_USERSHOWWINDOW, + wShowWindow=SW_MAXIMIZE + ) + # Since Python is a console process, it won't be affected + # by wShowWindow, but the argument should be silently + # ignored + subprocess.call([sys.executable, "-c", "import sys; sys.exit(0)"], + startupinfo=startupinfo) + def test_creationflags(self): # creationflags argument CREATE_NEW_CONSOLE = 16 |