Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-35246: fix support for path-like args in asyncio subprocess
drop isinstance checks from create_subprocess_exec function and let
subprocess module do them.
  • Loading branch information
lilydjwg committed May 28, 2019
commit d7dc43568a71ccda5079441b7829cfe3de36c9dc
5 changes: 0 additions & 5 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,11 +1605,6 @@ async def subprocess_exec(self, protocol_factory, program, *args,
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:
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,18 @@ async def execute():
self.loop.run_until_complete(execute())


def test_create_subprocess_exec_with_path(self):
async def execute():
from pathlib import Path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the import to the top of the module.
Use import pathlib form and pathlib.Path for consistency.

p = await subprocess.create_subprocess_exec(
Path(sys.executable), '-c', 'pass')
await p.wait()
p = await subprocess.create_subprocess_exec(
sys.executable, '-c', 'pass', Path('.'))
await p.wait()

self.loop.run_until_complete(execute())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add self.assertIsNone(loop.run_until_complete(...)) check to emphasize that we checked that the test passed correctly.


if sys.platform != 'win32':
# Unix
class SubprocessWatcherMixin(SubprocessMixin):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make :func:`asyncio.create_subprocess_exec` accept path-like arguments.