8000 gh-85984: Remove legacy Lib/pty.py code. (#92365) · python/cpython@244d4cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 244d4cd

Browse files
8vasublurb-it[bot]gpshead
authored
gh-85984: Remove legacy Lib/pty.py code. (#92365)
Refactored the implementation of pty.fork to use os.login_tty. A DeprecationWarning is now raised by pty.master_open() and pty.slave_open(). They were undocumented and deprecated long long ago in the docstring in favor of pty.openpty. Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
1 parent 65b7b6b commit 244d4cd

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ Pending Removal in Python 3.14
512512
:func:`~multiprocessing.set_start_method` APIs to explicitly specify when
513513
your code *requires* ``'fork'``. See :ref:`multiprocessing-start-methods`.
514514

515+
* :mod:`pty` has two undocumented ``master_open()`` and ``slave_open()``
516+
functions that have been deprecated since Python 2 but only gained a
517+
proper :exc:`DeprecationWarning` in 3.12. Remove them in 3.14.
518+
515519
Pending Removal in Future Versions
516520
----------------------------------
517521

Lib/pty.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def master_open():
4040
Open a pty master and return the fd, and the filename of the slave end.
4141
Deprecated, use openpty() instead."""
4242

43+
import warnings
44+
warnings.warn("Use pty.openpty() instead.", DeprecationWarning, stacklevel=2) # Remove API in 3.14
45+
4346
try:
4447
master_fd, slave_fd = os.openpty()
4548
except (AttributeError, OSError):
@@ -69,6 +72,9 @@ def slave_open(tty_name):
6972
opened filedescriptor.
7073
Deprecated, use openpty() instead."""
7174

75+
import warnings
76+
warnings.warn("Use pty.openpty() instead.", DeprecationWarning, stacklevel=2) # Remove API in 3.14
77+
7278
result = os.open(tty_name, os.O_RDWR)
7379
try:
7480
from fcntl import ioctl, I_PUSH
@@ -101,20 +107,8 @@ def fork():
101107
master_fd, slave_fd = openpty()
102108
pid = os.fork()
103109
if pid == CHILD:
104-
# Establish a new session.
105-
os.setsid()
106110
os.close(master_fd)
107-
108-
# Slave becomes stdin/stdout/stderr of child.
109-
os.dup2(slave_fd, STDIN_FILENO)
110-
os.dup2(slave_fd, STDOUT_FILENO)
111-
os.dup2(slave_fd, STDERR_FILENO)
112-
if slave_fd > STDERR_FILENO:
113-
os.close(slave_fd)
114-
115-
# Explicitly open the tty to make it become a controlling tty.
116-
tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR)
117-
os.close(tmp_fd)
111+
os.login_tty(slave_fd)
118112
else:
119113
os.close(slave_fd)
120114

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Refactored the implementation of :func:`pty.fork` to use :func:`os.login_tty`.
2+
3+
A :exc:`DeprecationWarning` is now raised by ``pty.master_open()`` and ``pty.slave_open()``. They were
4+
undocumented and deprecated long long ago in the docstring in favor of :func:`pty.openpty`.

0 commit comments

Comments
 (0)
0