From 67fb193cdd00cd955c57fdddce35d936a992b6c5 Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: Sat, 31 Oct 2026 18:18:13 -0400 Subject: [PATCH 1/2] gh-161039: Fix detection of `less >= 706` in `_pyrepl.pager.get_pager` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since less tag v706¹, less exits with a failure status when no filename is provided. Pass the `-?` option and redirect both stdout and stderr to /dev/null. Failure to detect `less` results in using `more` for users who don't have MANPAGER or PAGER set, which is unexpected. ¹ https://github.com/gwsw/less/commit/7c85230 (Exit with a failure status in more cases, 2026-06-14) --- Lib/_pyrepl/pager.py | 2 +- .../next/Library/2026-10-31-21-34-00.gh-issue-161040.k7_pTD.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161040.k7_pTD.rst diff --git a/Lib/_pyrepl/pager.py b/Lib/_pyrepl/pager.py index d6f20fe7557e6b3..2fad7e6e7fa21a6 100644 --- a/Lib/_pyrepl/pager.py +++ b/Lib/_pyrepl/pager.py @@ -36,7 +36,7 @@ def get_pager() -> Pager: return lambda text, title='': tempfile_pager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(pager) 2>/dev/null') == 0: return lambda text, title='': pipe_pager(text, 'pager', title) - if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: + if hasattr(os, 'system') and os.system('(less -?) >/dev/null 2>&1') == 0: return lambda text, title='': pipe_pager(text, 'less', title) import tempfile diff --git a/Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161040.k7_pTD.rst b/Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161040.k7_pTD.rst new file mode 100644 index 000000000000000..08f4f9994809014 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161040.k7_pTD.rst @@ -0,0 +1 @@ +Fix detection of ``less >= 706`` in :func:`_pyrepl.pager.get_pager`. From cfd09a3558849029ad13ab6ae91bd8c110be18a3 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sun, 1 Nov 2026 18:57:03 +0000 Subject: [PATCH 2/2] Minor adjustment to test and news entry --- Lib/_pyrepl/pager.py | 2 +- .../next/Library/2026-10-31-21-34-00.gh-issue-161039.k7_pTD.rst | 1 + .../next/Library/2026-10-31-21-34-00.gh-issue-161040.k7_pTD.rst | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161039.k7_pTD.rst delete mode 100644 Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161040.k7_pTD.rst diff --git a/Lib/_pyrepl/pager.py b/Lib/_pyrepl/pager.py index 2fad7e6e7fa21a6..eee4e3675fc36ee 100644 --- a/Lib/_pyrepl/pager.py +++ b/Lib/_pyrepl/pager.py @@ -36,7 +36,7 @@ def get_pager() -> Pager: return lambda text, title='': tempfile_pager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(pager) 2>/dev/null') == 0: return lambda text, title='': pipe_pager(text, 'pager', title) - if hasattr(os, 'system') and os.system('(less -?) >/dev/null 2>&1') == 0: + if hasattr(os, 'system') and os.system('(less -V) >/dev/null 2>&1') == 0: return lambda text, title='': pipe_pager(text, 'less', title) import tempfile diff --git a/Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161039.k7_pTD.rst b/Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161039.k7_pTD.rst new file mode 100644 index 000000000000000..3b697fb155b7aca --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161039.k7_pTD.rst @@ -0,0 +1 @@ +Fix the :mod:`pydoc` pager not detecting ``less`` 706 and newer. diff --git a/Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161040.k7_pTD.rst b/Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161040.k7_pTD.rst deleted file mode 100644 index 08f4f9994809014..000000000000000 --- a/Misc/NEWS.d/next/Library/2026-10-31-21-34-00.gh-issue-161040.k7_pTD.rst +++ /dev/null @@ -1 +0,0 @@ -Fix detection of ``less >= 706`` in :func:`_pyrepl.pager.get_pager`.