Skip to content

bpo-35345: Remove platform.popen() #10781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 0 additions & 14 deletions Doc/library/platform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,6 @@ Windows Platform
only runs on Win32 compatible platforms.


Win95/98 specific
^^^^^^^^^^^^^^^^^

.. function:: popen(cmd, mode='r', bufsize=-1)

Portable :func:`popen` interface. Find a working popen implementation
preferring :func:`win32pipe.popen`. On Windows NT, :func:`win32pipe.popen`
should work; on Windows 9x it hangs due to bugs in the MS C library.

.. deprecated:: 3.3
This function is obsolete. Use the :mod:`subprocess` module. Check
especially the :ref:`subprocess-replacements` section.


Mac OS Platform
---------------

Expand Down
12 changes: 10 additions & 2 deletions Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,13 @@ Deprecated
(Contributed by Serhiy Storchaka in :issue:`33710`.)


Removed
=======
API and Feature Removals
========================

The following features and APIs have been removed from Python 3.8:

* The function :func:`platform.popen` has been removed, it was deprecated since
Python 3.3: use :func:`os.popen` instead.

* The ``pyvenv`` script has been removed in favor of ``python3.8 -m venv``
to help eliminate confusion as to what Python interpreter the ``pyvenv``
Expand Down Expand Up @@ -414,6 +419,9 @@ Changes in Python behavior
Changes in the Python API
-------------------------

* The function :func:`platform.popen` has been removed, it was deprecated since
Python 3.3: use :func:`os.popen` instead.

* The :meth:`~tkinter.ttk.Treeview.selection` method of the
:class:`tkinter.ttk.Treeview` class no longer takes arguments. Using it with
arguments for changing the selection was deprecated in Python 3.6. Use
Expand Down
9 changes: 0 additions & 9 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,6 @@ def libc_ver(executable=sys.executable, lib='', version='', chunksize=16384):
pos = m.end()
return lib, version

def popen(cmd, mode='r', bufsize=-1):

""" Portable popen() interface.
"""
import warnings
warnings.warn('use os.popen instead', DeprecationWarning, stacklevel=2)
return os.popen(cmd, mode, bufsize)


def _norm_version(version, build=''):

""" Normalize the version and build strings and return a single
Expand Down
33 changes: 0 additions & 33 deletions Lib/test/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import subprocess
import sys
import sysconfig
import tempfile
import unittest
import warnings

from test import support

Expand Down Expand Up @@ -316,37 +314,6 @@ def test__comparable_version(self):
self.assertLess(V('1.13++'), V('5.5.kw'))
self.assertLess(V('0.960923'), V('2.2beta29'))

def test_popen(self):
mswindows = (sys.platform == "win32")

if mswindows:
command = '"{}" -c "print(\'Hello\')"'.format(sys.executable)
else:
command = "'{}' -c 'print(\"Hello\")'".format(sys.executable)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with platform.popen(command) as stdout:
hello = stdout.read().strip()
stdout.close()
self.assertEqual(hello, "Hello")

data = 'plop'
if mswindows:
command = '"{}" -c "import sys; data=sys.stdin.read(); exit(len(data))"'
else:
command = "'{}' -c 'import sys; data=sys.stdin.read(); exit(len(data))'"
command = command.format(sys.executable)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with platform.popen(command, 'w') as stdin:
stdout = stdin.write(data)
ret = stdin.close()
self.assertIsNotNone(ret)
if os.name == 'nt':
returncode = ret
else:
returncode = ret >> 8
self.assertEqual(returncode, len(data))

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The function `platform.popen` has been removed, it was deprecated since Python
3.3: use :func:`os.popen` instead.