Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 738131d

Browse files
committed
Raise TypeError if bufsize argument is not an integer. Patch 1071755, slightly modified.
1 parent 6fdf3cb commit 738131d

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/subprocess.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ def __init__(self, args, bufsize=0, executable=None,
504504
"""Create new Popen instance."""
505505
_cleanup()
506506

507+
if not isinstance(bufsize, (int, long)):
508+
raise TypeError("bufsize must be an integer")
509+
507510
if mswindows:
508511
if preexec_fn is not None:
509512
raise ValueError("preexec_fn is not supported on Windows "

Lib/test/test_subprocess.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,17 @@ def test_wait(self):
394394
# Subsequent invocations should just return the returncode
395395
self.assertEqual(p.wait(), 0)
396396

397+
398+
def test_invalid_bufsize(self):
399+
# an invalid type of the bufsize argument should raise
400+
# TypeError.
401+
try:
402+
subprocess.Popen([sys.executable, "-c", "pass"], "orange")
403+
except TypeError:
404+
pass
405+
else:
406+
self.fail("Expected TypeError")
407+
397408
#
398409
# POSIX tests
399410
#

0 commit comments

Comments
 (0)