Skip to content

Commit 03d755f

Browse files
committed
bpo-26128: Added __init__to STARTUPINFO
- Added tests for the code - Added docs
1 parent 21024f0 commit 03d755f

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

Doc/library/subprocess.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,8 @@ on Windows.
746746

747747
Partial support of the Windows
748748
`STARTUPINFO <https://msdn.microsoft.com/en-us/library/ms686331(v=vs.85).aspx>`__
749-
structure is used for :class:`Popen` creation.
749+
structure is used for :class:`Popen` creation. The following attributes can be set
750+
by passing them as keyword-only arguments.
750751

751752
.. attribute:: dwFlags
752753

@@ -788,6 +789,8 @@ on Windows.
788789
:data:`SW_HIDE` is provided for this attribute. It is used when
789790
:class:`Popen` is called with ``shell=True``.
790791

792+
.. versionchanged:: 3.7
793+
*Keyword-only argument* support was added.
791794

792795
Constants
793796
^^^^^^^^^

Lib/subprocess.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,13 @@ def stdout(self, value):
127127
import msvcrt
128128
import _winapi
129129
class STARTUPINFO:
130-
dwFlags = 0
131-
hStdInput = None
132-
hStdOutput = None
133-
hStdError = None
134-
wShowWindow = 0
130+
def __init__(self, *, dwFlags=0, hStdInput=None, hStdOutput=None,
131+
hStdError=None, wShowWindow=0):
132+
self.dwFlags = dwFlags
133+
self.hStdInput = hStdInput
134+
self.hStdOutput = hStdOutput
135+
self.hStdError = hStdError
136+
self.wShowWindow = wShowWindow
135137
else:
136138
import _posixsubprocess
137139
import select

Lib/test/test_subprocess.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,22 @@ def test_startupinfo(self):
25502550
subprocess.call([sys.executable, "-c", "import sys; sys.exit(0)"],
25512551
startupinfo=startupinfo)
25522552

2553+
def test_startupinfo_keywords(self):
2554+
# startupinfo argument
2555+
# We use hardcoded constants, because we do not want to
2556+
# depend on win32all.
2557+
STARTF_USERSHOWWINDOW = 1
2558+
SW_MAXIMIZE = 3
2559+
startupinfo = subprocess.STARTUPINFO(
2560+
dwFlags=STARTF_USERSHOWWINDOW,
2561+
wShowWindow=SW_MAXIMIZE
2562+
)
2563+
# Since Python is a console process, it won't be affected
2564+
# by wShowWindow, but the argument should be silently
2565+
# ignored
2566+
subprocess.call([sys.executable, "-c", "import sys; sys.exit(0)"],
2567+
startupinfo=startupinfo)
2568+
25532569
def test_creationflags(self):
25542570
# creationflags argument
25552571
CREATE_NEW_CONSOLE = 16

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,3 +1726,4 @@ Doug Zongker
17261726
Peter Åstrand
17271727
evilzero
17281728
Dhushyanth Ramasamy
1729+
Subhendu Ghosh

Misc/NEWS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Core and Builtins
1313
- bpo-28598: Support __rmod__ for subclasses of str being called before
1414
str.__mod__. Patch by Martijn Pieters.
1515

16-
- bpo-29607: Fix stack_effect computation for CALL_FUNCTION_EX.
16+
- bpo-29607: Fix stack_effect computation for CALL_FUNCTION_EX.
1717
Patch by Matthieu Dartiailh.
1818

1919
- bpo-29602: Fix incorrect handling of signed zeros in complex constructor for
@@ -1243,6 +1243,9 @@ Core and Builtins
12431243
Library
12441244
-------
12451245

1246+
- Issue #26128: Added keyword-only arguments support for
1247+
subprocess.STARTUPINFO
1248+
12461249
- Issue #27517: LZMA compressor and decompressor no longer raise exceptions if
12471250
given empty data twice. Patch by Benjamin Fogle.
12481251

0 commit comments

Comments
 (0)