]> granicus.if.org Git - python/commitdiff
bpo-26128: Added __init__to subprocess.STARTUPINFO (#171)
authorSubhendu Ghosh <subho.prp@gmail.com>
Sat, 25 Feb 2017 14:59:05 +0000 (20:29 +0530)
committerNick Coghlan <ncoghlan@gmail.com>
Sat, 25 Feb 2017 14:59:05 +0000 (00:59 +1000)
The Windows-specific subprocess.STARTUPINFO class now accepts
keyword-only arguments to its constructor to set the various
data attributes.

Patch by Subhendu Ghosh.

Doc/library/subprocess.rst
Lib/subprocess.py
Lib/test/test_subprocess.py
Misc/ACKS
Misc/NEWS

index ea065b897e1473dfa2fb7c7a273420e0c510be58..e9ba15eec1c20bd687fe050424c88c61a32e3a4f 100644 (file)
@@ -746,7 +746,8 @@ on Windows.
 
    Partial support of the Windows
    `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
 
@@ -788,6 +789,8 @@ on Windows.
       :data:`SW_HIDE` is provided for this attribute. It is used when
       :class:`Popen` is called with ``shell=True``.
 
+   .. versionchanged:: 3.7
+      *Keyword-only argument* support was added.
 
 Constants
 ^^^^^^^^^
index 67b9c9f1b16f4c52a0110ab8e34d9ee63f61dd2b..dffcda3e9fbbc0a76a3f0728d7822d5e80677311 100644 (file)
@@ -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
index 82e0b870af0fae717cb208ad07e8cce2e632bc6f..812e7bf2cc8a7291017d564f264aed54b44421f5 100644 (file)
@@ -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
index 255318e572492dce22d6ae0af7419dee7049a4a1..1995adb371e97017c62f6685c7a5c2ab749493ca 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1726,3 +1726,4 @@ Doug Zongker
 Peter Åstrand
 evilzero
 Dhushyanth Ramasamy
+Subhendu Ghosh
index 74ec8c3bdf26e3d12bc76b3dfcfb19a72a8effd1..4413c511157fcd18a177c2e6152cbf24c0e0e5ec 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,7 +13,7 @@ Core and Builtins
 - bpo-28598: Support __rmod__ for subclasses of str being called before
   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.
 
 - bpo-29602: Fix incorrect handling of signed zeros in complex constructor for
@@ -1243,6 +1243,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #26128: Added keyword-only arguments support for
+  subprocess.STARTUPINFO
+
 - Issue #27517: LZMA compressor and decompressor no longer raise exceptions if
   given empty data twice.  Patch by Benjamin Fogle.