Skip to content

Commit 73104fa

Browse files
authored
bpo-35345: Remove platform.popen() (GH-10781)
Remove platform.popen() function, it was deprecated since Python 3.3: use os.popen() instead. Rename also the "Removed" section to "API and Feature Removals" of What's New in Python 3.8.
1 parent 7cc1fa4 commit 73104fa

File tree

5 files changed

+12
-58
lines changed

5 files changed

+12
-58
lines changed

Doc/library/platform.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,6 @@ Windows Platform
212212
only runs on Win32 compatible platforms.
213213

214214

215-
Win95/98 specific
216-
^^^^^^^^^^^^^^^^^
217-
218-
.. function:: popen(cmd, mode='r', bufsize=-1)
219-
220-
Portable :func:`popen` interface. Find a working popen implementation
221-
preferring :func:`win32pipe.popen`. On Windows NT, :func:`win32pipe.popen`
222-
should work; on Windows 9x it hangs due to bugs in the MS C library.
223-
224-
.. deprecated:: 3.3
225-
This function is obsolete. Use the :mod:`subprocess` module. Check
226-
especially the :ref:`subprocess-replacements` section.
227-
228-
229215
Mac OS Platform
230216
---------------
231217

Doc/whatsnew/3.8.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,13 @@ Deprecated
373373
(Contributed by Serhiy Storchaka in :issue:`33710`.)
374374

375375

376-
Removed
377-
=======
376+
API and Feature Removals
377+
========================
378+
379+
The following features and APIs have been removed from Python 3.8:
380+
381+
* The function :func:`platform.popen` has been removed, it was deprecated since
382+
Python 3.3: use :func:`os.popen` instead.
378383

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

422+
* The function :func:`platform.popen` has been removed, it was deprecated since
423+
Python 3.3: use :func:`os.popen` instead.
424+
417425
* The :meth:`~tkinter.ttk.Treeview.selection` method of the
418426
:class:`tkinter.ttk.Treeview` class no longer takes arguments. Using it with
419427
arguments for changing the selection was deprecated in Python 3.6. Use

Lib/platform.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,6 @@ def libc_ver(executable=sys.executable, lib='', version='', chunksize=16384):
227227
pos = m.end()
228228
return lib, version
229229

230-
def popen(cmd, mode='r', bufsize=-1):
231-
232-
""" Portable popen() interface.
233-
"""
234-
import warnings
235-
warnings.warn('use os.popen instead', DeprecationWarning, stacklevel=2)
236-
return os.popen(cmd, mode, bufsize)
237-
238-
239230
def _norm_version(version, build=''):
240231

241232
""" Normalize the version and build strings and return a single

Lib/test/test_platform.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import subprocess
44
import sys
55
import sysconfig
6-
import tempfile
76
import unittest
8-
import warnings
97

108
from test import support
119

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

319-
def test_popen(self):
320-
mswindows = (sys.platform == "win32")
321-
322-
if mswindows:
323-
command = '"{}" -c "print(\'Hello\')"'.format(sys.executable)
324-
else:
325-
command = "'{}' -c 'print(\"Hello\")'".format(sys.executable)
326-
with warnings.catch_warnings():
327-
warnings.simplefilter("ignore", DeprecationWarning)
328-
with platform.popen(command) as stdout:
329-
hello = stdout.read().strip()
330-
stdout.close()
331-
self.assertEqual(hello, "Hello")
332-
333-
data = 'plop'
334-
if mswindows:
335-
command = '"{}" -c "import sys; data=sys.stdin.read(); exit(len(data))"'
336-
else:
337-
command = "'{}' -c 'import sys; data=sys.stdin.read(); exit(len(data))'"
338-
command = command.format(sys.executable)
339-
with warnings.catch_warnings():
340-
warnings.simplefilter("ignore", DeprecationWarning)
341-
with platform.popen(command, 'w') as stdin:
342-
stdout = stdin.write(data)
343-
ret = stdin.close()
344-
self.assertIsNotNone(ret)
345-
if os.name == 'nt':
346-
returncode = ret
347-
else:
348-
returncode = ret >> 8
349-
self.assertEqual(returncode, len(data))
350317

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

0 commit comments

Comments
 (0)