]> granicus.if.org Git - python/commitdiff
bpo-35246: fix support for path-like args in asyncio subprocess (GH-13628)
author依云 <lilydjwg@gmail.com>
Wed, 29 May 2019 06:50:59 +0000 (14:50 +0800)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 29 May 2019 06:50:59 +0000 (23:50 -0700)
Drop isinstance checks from create_subprocess_exec function and let
subprocess module do them.

https://bugs.python.org/issue35246

https://bugs.python.org/issue35246

Lib/asyncio/base_events.py
Lib/test/test_asyncio/test_subprocess.py
Misc/NEWS.d/next/Library/2019-05-28-23-17-35.bpo-35246.oXT21d.rst [new file with mode: 0644]

index 68105eec8132e7725cdbdbedf8ddf8ece0130ed3..e0025397fa8a85c883341e878371ec57854167f1 100644 (file)
@@ -1605,11 +1605,6 @@ class BaseEventLoop(events.AbstractEventLoop):
             raise ValueError("errors must be None")
 
         popen_args = (program,) + args
-        for arg in popen_args:
-            if not isinstance(arg, (str, bytes)):
-                raise TypeError(
-                    f"program arguments must be a bytes or text string, "
-                    f"not {type(arg).__name__}")
         protocol = protocol_factory()
         debug_log = None
         if self._debug:
index f1ab039ad6639b4c005e78d07d4576a01db693db..7d72e6cde4e7a840cda09076490a354bd08df6db 100644 (file)
@@ -622,6 +622,17 @@ class SubprocessMixin:
         self.loop.run_until_complete(execute())
 
 
+    def test_create_subprocess_exec_with_path(self):
+        async def execute():
+            p = await subprocess.create_subprocess_exec(
+                support.FakePath(sys.executable), '-c', 'pass')
+            await p.wait()
+            p = await subprocess.create_subprocess_exec(
+                sys.executable, '-c', 'pass', support.FakePath('.'))
+            await p.wait()
+
+        self.assertIsNone(self.loop.run_until_complete(execute()))
+
 if sys.platform != 'win32':
     # Unix
     class SubprocessWatcherMixin(SubprocessMixin):
diff --git a/Misc/NEWS.d/next/Library/2019-05-28-23-17-35.bpo-35246.oXT21d.rst b/Misc/NEWS.d/next/Library/2019-05-28-23-17-35.bpo-35246.oXT21d.rst
new file mode 100644 (file)
index 0000000..39d4469
--- /dev/null
@@ -0,0 +1 @@
+Make :func:`asyncio.create_subprocess_exec` accept path-like arguments.