summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-05-19 03:12:47 (GMT)
committerGitHub <noreply@github.com>2022-05-19 03:12:47 (GMT)
commitaa55985aa85ebad5409ed5485fd4957d5ca28f94 (patch)
tree750b0fe6460e6944d235b06b06f9720a945035d8
parent849963598fa0454ef1bc9c93f5654d63f59e830d (diff)
downloadcpython-aa55985aa85ebad5409ed5485fd4957d5ca28f94.zip
cpython-aa55985aa85ebad5409ed5485fd4957d5ca28f94.tar.gz
cpython-aa55985aa85ebad5409ed5485fd4957d5ca28f94.tar.bz2
gh-87901: Remove the encoding argument from os.popen (GH-92836)
(cherry picked from commit 96f65835f8f66d058b444e0b4e436af45e2902f7) Co-authored-by: Inada Naoki <songofacandy@gmail.com>
-rw-r--r--Doc/library/os.rst13
-rw-r--r--Lib/os.py5
-rw-r--r--Misc/NEWS.d/next/Library/2022-05-18-21-04-09.gh-issue-87901.lnf041.rst2
3 files changed, 13 insertions, 7 deletions
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 3c189bb..dc0f2e4 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -3916,13 +3916,13 @@ written in Python, such as a mail server's external command delivery program.
.. availability:: Unix.
-.. function:: popen(cmd, mode='r', buffering=-1, encoding=None)
+.. function:: popen(cmd, mode='r', buffering=-1)
Open a pipe to or from command *cmd*.
The return value is an open file object
connected to the pipe, which can be read or written depending on whether *mode*
is ``'r'`` (default) or ``'w'``.
- The *buffering* and *encoding* arguments have the same meaning as
+ The *buffering* argument have the same meaning as
the corresponding argument to the built-in :func:`open` function. The
returned file object reads or writes text strings rather than bytes.
@@ -3945,8 +3945,13 @@ written in Python, such as a mail server's external command delivery program.
documentation for more powerful ways to manage and communicate with
subprocesses.
- .. versionchanged:: 3.11
- Added the *encoding* parameter.
+ .. note::
+ The :ref:`Python UTF-8 Mode <utf8-mode>` affects encodings used
+ for *cmd* and pipe contents.
+
+ :func:`popen` is a simple wrapper around :class:`subprocess.Popen`.
+ Use :class:`subprocess.Popen` or :func:`subprocess.run` to
+ control options like encodings.
.. function:: posix_spawn(path, argv, env, *, file_actions=None, \
diff --git a/Lib/os.py b/Lib/os.py
index 67662ca..648188e 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -974,15 +974,14 @@ otherwise return -SIG, where SIG is the signal that killed it. """
# command in a shell can't be supported.
if sys.platform != 'vxworks':
# Supply os.popen()
- def popen(cmd, mode="r", buffering=-1, encoding=None):
+ def popen(cmd, mode="r", buffering=-1):
if not isinstance(cmd, str):
raise TypeError("invalid cmd type (%s, expected string)" % type(cmd))
if mode not in ("r", "w"):
raise ValueError("invalid mode %r" % mode)
if buffering == 0 or buffering is None:
raise ValueError("popen() does not support unbuffered streams")
- import subprocess, io
- encoding = io.text_encoding(encoding)
+ import subprocess
if mode == "r":
proc = subprocess.Popen(cmd,
shell=True, text=True,
diff --git a/Misc/NEWS.d/next/Library/2022-05-18-21-04-09.gh-issue-87901.lnf041.rst b/Misc/NEWS.d/next/Library/2022-05-18-21-04-09.gh-issue-87901.lnf041.rst
new file mode 100644
index 0000000..3488541
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-05-18-21-04-09.gh-issue-87901.lnf041.rst
@@ -0,0 +1,2 @@
+Removed the ``encoding`` argument from :func:`os.popen` that was added in
+3.11b1.