Skip to content

Commit

Permalink
bpo-26128: Added __init__to STARTUPINFO
Browse files Browse the repository at this point in the history
- Added tests for the code
- Added docs
  • Loading branch information
codenamesubho committed Feb 25, 2017
1 parent 21024f0 commit 03d755f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Doc/library/subprocess.rst
Expand Up @@ -746,7 +746,8 @@ on Windows.


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


.. attribute:: dwFlags .. attribute:: dwFlags


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


.. versionchanged:: 3.7
*Keyword-only argument* support was added.


Constants Constants
^^^^^^^^^ ^^^^^^^^^
Expand Down
12 changes: 7 additions & 5 deletions Lib/subprocess.py
Expand Up @@ -127,11 +127,13 @@ def stdout(self, value):
import msvcrt import msvcrt
import _winapi import _winapi
class STARTUPINFO: class STARTUPINFO:
dwFlags = 0 def __init__(self, *, dwFlags=0, hStdInput=None, hStdOutput=None,
hStdInput = None hStdError=None, wShowWindow=0):
hStdOutput = None self.dwFlags = dwFlags
hStdError = None self.hStdInput = hStdInput
wShowWindow = 0 self.hStdOutput = hStdOutput
self.hStdError = hStdError
self.wShowWindow = wShowWindow
else: else:
import _posixsubprocess import _posixsubprocess
import select import select
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_subprocess.py
Expand Up @@ -2550,6 +2550,22 @@ def test_startupinfo(self):
subprocess.call([sys.executable, "-c", "import sys; sys.exit(0)"], subprocess.call([sys.executable, "-c", "import sys; sys.exit(0)"],
startupinfo=startupinfo) 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): def test_creationflags(self):
# creationflags argument # creationflags argument
CREATE_NEW_CONSOLE = 16 CREATE_NEW_CONSOLE = 16
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Expand Up @@ -1726,3 +1726,4 @@ Doug Zongker
Peter Åstrand Peter Åstrand
evilzero evilzero
Dhushyanth Ramasamy Dhushyanth Ramasamy
Subhendu Ghosh
5 changes: 4 additions & 1 deletion Misc/NEWS
Expand Up @@ -13,7 +13,7 @@ Core and Builtins
- bpo-28598: Support __rmod__ for subclasses of str being called before - bpo-28598: Support __rmod__ for subclasses of str being called before
str.__mod__. Patch by Martijn Pieters. str.__mod__. Patch by Martijn Pieters.


- bpo-29607: Fix stack_effect computation for CALL_FUNCTION_EX. - bpo-29607: Fix stack_effect computation for CALL_FUNCTION_EX.
Patch by Matthieu Dartiailh. Patch by Matthieu Dartiailh.


- bpo-29602: Fix incorrect handling of signed zeros in complex constructor for - bpo-29602: Fix incorrect handling of signed zeros in complex constructor for
Expand Down Expand Up @@ -1243,6 +1243,9 @@ Core and Builtins
Library Library
------- -------


- Issue #26128: Added keyword-only arguments support for
subprocess.STARTUPINFO

- Issue #27517: LZMA compressor and decompressor no longer raise exceptions if - Issue #27517: LZMA compressor and decompressor no longer raise exceptions if
given empty data twice. Patch by Benjamin Fogle. given empty data twice. Patch by Benjamin Fogle.


Expand Down

0 comments on commit 03d755f

Please sign in to comment.