Skip to content

gh-161039: fix detection of less >= 706 in _pyrepl/pager.py - #161040

Merged
StanFromIreland merged 2 commits into
python:mainfrom
tmzullinger:pyrepl-pager-fix-less-detection
Nov 1, 2026
Merged

StanFromIreland merged 2 commits into
python:mainfrom
tmzullinger:pyrepl-pager-fix-less-detection

Conversation

@tmzullinger

@tmzullinger tmzullinger commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

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.

¹ gwsw/less@7c85230 (Exit with a failure
status in more cases, 2026-06-14)

@python-cla-bot

python-cla-bot Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Oct 31, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@tmzullinger

Copy link
Copy Markdown
Contributor Author

This could be handled in various ways. Using less -? seemed like a clear and easy way to go. It is supported by less for many, many years. (I didn't check the code history, but a system with less-436 shows the -? option there.)

…_pager`

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.

¹ gwsw/less@7c85230 (Exit with a failure
  status in more cases, 2026-06-14)
@tmzullinger
tmzullinger force-pushed the pyrepl-pager-fix-less-detection branch from 72a8316 to 67fb193 Compare November 1, 2026 01:41
@tmzullinger

Copy link
Copy Markdown
Contributor Author

Apparently, I should not have bothered adding a NEWS snippet after the initial feedback from the bot. Or at the least, I don't know enough about the syntax to write one that passes the doc checks.

If someone can offer advice on fixing whatever is wrong with the snippet or whether it's even needed for the simple code fix, I'll happily change it either way.

@StanFromIreland

Copy link
Copy Markdown
Member

I pushed a little change to test with less -V instead of less -?, there's no shell glob so it's a little safer IMO. I also slightly reworded the news entry to explain the user-facing issue.

@StanFromIreland
StanFromIreland enabled auto-merge (squash) November 1, 2026 19:00
@StanFromIreland StanFromIreland added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 1, 2026
@tmzullinger

Copy link
Copy Markdown
Contributor Author

I pushed a little change to test with less -V instead of less -?, there's no shell glob so it's a little safer IMO. I also slightly reworded the news entry to explain the user-facing issue.

Thanks! I can update the commit message to match, if that level of consistency is important to anyone.

Indeed it's better to avoid -? in the case someone has a file with -<char> in the working directory. I should have thought about this due to the use of the shell via os.system. I used --help initially but wanted to shorten it so I didn't have to think more about how and where you might want the code wrapped. And less (being quite old) uses -h for other things.

(I did wonder why os.system was used instead of subprocess or something else. Is that intentional, perhaps to avoid more dependencies, or just quirk of how the pager code evolved?)

FWIW, I checked the less history and both -? and -V are both supported practically forever. -? was added in fe6f798 (Initial revision, 1994-10-15) (tag v243). -V was added a few weeks later in 0aae6ed (Add -V option., 1994-11-01) (tag v250). :)

@StanFromIreland
StanFromIreland merged commit 2f20512 into python:main Nov 1, 2026
70 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @tmzullinger for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@tmzullinger
tmzullinger deleted the pyrepl-pager-fix-less-detection branch November 1, 2026 19:44
@StanFromIreland

Copy link
Copy Markdown
Member

Merged, thanks!

Is that intentional, perhaps to avoid more dependencies, or just quirk of how the pager code evolved?

I presume the pager predates subprocess, and I don't think there's enough reason to switch currently.

Hmm, I'll try backporting again tomorrow, the bot seems to be down.

@hugovk hugovk added needs backport to 3.15 bugs and security fixes and removed needs backport to 3.15 bugs and security fixes labels Nov 1, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @tmzullinger for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@hugovk hugovk added needs backport to 3.15 bugs and security fixes and removed needs backport to 3.15 bugs and security fixes labels Nov 1, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @tmzullinger for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 1, 2026

Copy link
Copy Markdown

GH-161148 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 1, 2026
@hugovk hugovk added needs backport to 3.14 bugs and security fixes and removed needs backport to 3.14 bugs and security fixes labels Nov 1, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @tmzullinger for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 1, 2026

Copy link
Copy Markdown

GH-161149 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants