From 37b23888715f2a48e63465677fc0fa3f495bb101 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 9 May 2024 11:51:35 +0300 Subject: [PATCH 1/2] gh-118824: Remove deprecated `master_open` and `slave_open` from `pty` --- Doc/whatsnew/3.14.rst | 3 ++ Lib/pty.py | 39 ------------------- ...-05-09-11-50-26.gh-issue-118824.-jBJQC.rst | 1 + 3 files changed, 4 insertions(+), 39 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-05-09-11-50-26.gh-issue-118824.-jBJQC.rst diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 5aa6e4f7a9ed3e..73ae29d0b4e289 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -109,6 +109,9 @@ Removed are removed. They had previously raised a :exc:`DeprecationWarning` since Python 3.12. +* Remove deprecated ``pty.master_open`` and ``pty.slave_open``. + They had previously raised a :exc:`DeprecationWarning` since Python 3.12. + Porting to Python 3.14 ====================== diff --git a/Lib/pty.py b/Lib/pty.py index 1d97994abef3c8..365c638027341c 100644 --- a/Lib/pty.py +++ b/Lib/pty.py @@ -35,25 +35,6 @@ def openpty(): slave_fd = slave_open(slave_name) return master_fd, slave_fd -def master_open(): - """master_open() -> (master_fd, slave_name) - Open a pty master and return the fd, and the filename of the slave end. - Deprecated, use openpty() instead.""" - - import warnings - warnings.warn("Use pty.openpty() instead.", DeprecationWarning, stacklevel=2) # Remove API in 3.14 - - try: - master_fd, slave_fd = os.openpty() - except (AttributeError, OSError): - pass - else: - slave_name = os.ttyname(slave_fd) - os.close(slave_fd) - return master_fd, slave_name - - return _open_terminal() - def _open_terminal(): """Open pty master and return (master_fd, tty_name).""" for x in 'pqrstuvwxyzPQRST': @@ -66,26 +47,6 @@ def _open_terminal(): return (fd, '/dev/tty' + x + y) raise OSError('out of pty devices') -def slave_open(tty_name): - """slave_open(tty_name) -> slave_fd - Open the pty slave and acquire the controlling terminal, returning - opened filedescriptor. - Deprecated, use openpty() instead.""" - - import warnings - warnings.warn("Use pty.openpty() instead.", DeprecationWarning, stacklevel=2) # Remove API in 3.14 - - result = os.open(tty_name, os.O_RDWR) - try: - from fcntl import ioctl, I_PUSH - except ImportError: - return result - try: - ioctl(result, I_PUSH, "ptem") - ioctl(result, I_PUSH, "ldterm") - except OSError: - pass - return result def fork(): """fork() -> (pid, master_fd) diff --git a/Misc/NEWS.d/next/Library/2024-05-09-11-50-26.gh-issue-118824.-jBJQC.rst b/Misc/NEWS.d/next/Library/2024-05-09-11-50-26.gh-issue-118824.-jBJQC.rst new file mode 100644 index 00000000000000..a51e5bebb1b9a5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-05-09-11-50-26.gh-issue-118824.-jBJQC.rst @@ -0,0 +1 @@ +Remove deprecated ``pty.master_open`` and ``pty.slave_open``. From c73b3252633c47bd2a3e3960576453df9b2c9d1f Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Tue, 28 May 2024 13:52:41 +0300 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/whatsnew/3.14.rst | 4 +++- .../Library/2024-05-09-11-50-26.gh-issue-118824.-jBJQC.rst | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index c9796228c7be7f..c82037de84a144 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -148,8 +148,10 @@ pathlib pty ___ -* Remove deprecated ``pty.master_open`` and ``pty.slave_open``. +* Remove deprecated :func:`!pty.master_open` and :func:`!pty.slave_open`. They had previously raised a :exc:`DeprecationWarning` since Python 3.12. + Use :func:`pty.openpty` instead. + (Contributed by Nikita Sobolev in :gh:`118824`.) sqlite3 ------- diff --git a/Misc/NEWS.d/next/Library/2024-05-09-11-50-26.gh-issue-118824.-jBJQC.rst b/Misc/NEWS.d/next/Library/2024-05-09-11-50-26.gh-issue-118824.-jBJQC.rst index a51e5bebb1b9a5..c9254f1b9dbea8 100644 --- a/Misc/NEWS.d/next/Library/2024-05-09-11-50-26.gh-issue-118824.-jBJQC.rst +++ b/Misc/NEWS.d/next/Library/2024-05-09-11-50-26.gh-issue-118824.-jBJQC.rst @@ -1 +1,3 @@ -Remove deprecated ``pty.master_open`` and ``pty.slave_open``. +Remove deprecated :func:`!pty.master_open` and :func:`!pty.slave_open`. +Use :func:`pty.openpty` instead. +Patch by Nikita Sobolev.