Issue 16903: subprocess.Popen.communicate with universal_newlines=True doesn't accept strings on 3.2 (original) (raw)

On 3.2 subprocess.Popen.communicate with universal_newlines=True accepts bytes and doesn't accept strings.

$ ./python -c "import subprocess; subprocess.Popen(['cat'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True).communicate('qwerty')" Traceback (most recent call last): File "", line 1, in File "/home/serhiy/py/cpython3.2/Lib/subprocess.py", line 833, in communicate return self._communicate(input) File "/home/serhiy/py/cpython3.2/Lib/subprocess.py", line 1470, in _communicate stdout, stderr = self._communicate_with_poll(input) File "/home/serhiy/py/cpython3.2/Lib/subprocess.py", line 1537, in _communicate_with_poll input_offset += os.write(fd, chunk) TypeError: 'str' does not support the buffer interface

On 3.3+ it accepts strings and doesn't accept bytes.

Indeed, Popen.communicate() is incompatible not only between 3.2 and 3.3, but between Windows and POSIX too.

Documentation says the input argument should be a bytes string and 3.2 on POSIX works only with bytes strings. 3.2 on Windows and 3.3 on both platforms require an unicode string, as 3.3 documentation says. 3.2 on Windows hangs with a bytes string.

Patch updated with the documentation change (copied from 3.3).