Skip to content

Commit 96f6583

Browse files
authored
gh-87901: Remove the encoding argument from os.popen (GH-92836)
1 parent f2d994d commit 96f6583

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Doc/library/os.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,13 +3916,13 @@ written in Python, such as a mail server's external command delivery program.
39163916
.. availability:: Unix.
39173917

39183918

3919-
.. function:: popen(cmd, mode='r', buffering=-1, encoding=None)
3919+
.. function:: popen(cmd, mode='r', buffering=-1)
39203920

39213921
Open a pipe to or from command *cmd*.
39223922
The return value is an open file object
39233923
connected to the pipe, which can be read or written depending on whether *mode*
39243924
is ``'r'`` (default) or ``'w'``.
3925-
The *buffering* and *encoding* arguments have the same meaning as
3925+
The *buffering* argument have the same meaning as
39263926
the corresponding argument to the built-in :func:`open` function. The
39273927
returned file object reads or writes text strings rather than bytes.
39283928

@@ -3945,8 +3945,13 @@ written in Python, such as a mail server's external command delivery program.
39453945
documentation for more powerful ways to manage and communicate with
39463946
subprocesses.
39473947

3948-
.. versionchanged:: 3.11
3949-
Added the *encoding* parameter.
3948+
.. note::
3949+
The :ref:`Python UTF-8 Mode <utf8-mode>` affects encodings used
3950+
for *cmd* and pipe contents.
3951+
3952+
:func:`popen` is a simple wrapper around :class:`subprocess.Popen`.
3953+
Use :class:`subprocess.Popen` or :func:`subprocess.run` to
3954+
control options like encodings.
39503955

39513956

39523957
.. function:: posix_spawn(path, argv, env, *, file_actions=None, \

Lib/os.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,15 +974,14 @@ def spawnlpe(mode, file, *args):
974974
# command in a shell can't be supported.
975975
if sys.platform != 'vxworks':
976976
# Supply os.popen()
977-
def popen(cmd, mode="r", buffering=-1, encoding=None):
977+
def popen(cmd, mode="r", buffering=-1):
978978
if not isinstance(cmd, str):
979979
raise TypeError("invalid cmd type (%s, expected string)" % type(cmd))
980980
if mode not in ("r", "w"):
981981
raise ValueError("invalid mode %r" % mode)
982982
if buffering == 0 or buffering is None:
983983
raise ValueError("popen() does not support unbuffered streams")
984-
import subprocess, io
985-
encoding = io.text_encoding(encoding)
984+
import subprocess
986985
if mode == "r":
987986
proc = subprocess.Popen(cmd,
988987
shell=True, text=True,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Removed the ``encoding`` argument from :func:`os.popen` that was added in
2+
3.11b1.

0 commit comments

Comments
 (0)