Skip to content

gh-148468: Accept string-like help proxies in argparse#150276

Open
RaghunandanKumar wants to merge 3 commits into
python:mainfrom
RaghunandanKumar:fix-argparse-string-like-help
Open

gh-148468: Accept string-like help proxies in argparse#150276
RaghunandanKumar wants to merge 3 commits into
python:mainfrom
RaghunandanKumar:fix-argparse-string-like-help

Conversation

@RaghunandanKumar
Copy link
Copy Markdown

Summary

  • restore support for string-like proxy objects in colorized argparse descriptions, epilogs, and argument help text
  • normalize formatter text at the string-formatting boundary instead of assuming concrete str objects
  • add regression coverage for proxied descriptions, epilogs, and interpolated help text

Issue

Testing

  • ./python.exe -m test test_argparse
  • runtime repro with a minimal LazyStr proxy and parser.format_help()

Copy link
Copy Markdown
Member

@savannahostrowski savannahostrowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! As mentioned in my comment on the issue, the str() coercion can go at the re.sub call site rather than at the top of _expand_help. Also, please scope the change down. The _format_action changes and the broader test expansion aren't necessary for this fix.

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 23, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@savannahostrowski savannahostrowski added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 23, 2026
@RaghunandanKumar
Copy link
Copy Markdown
Author

Addressed review feedback:

  • moved str() coercion to re.sub() call site in _expand_help()
  • removed _format_action changes
  • trimmed regression coverage down to focused interpolated help proxy test

Testing:

  • ./python.exe -m test test_argparse

I have made the requested changes; please review again

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 26, 2026

Thanks for making the requested changes!

@savannahostrowski: please review the changes made to this pull request.

@bedevere-app bedevere-app Bot requested a review from savannahostrowski May 26, 2026 23:23
@RaghunandanKumar
Copy link
Copy Markdown
Author

Inspected the Win32 failure. test_argparse passed there; the red job is unrelated: test_profiling.test_sampling_profiler.test_generator_not_under_consumer_arithmetic in Windows / Build and test (Win32, switch-case).

This matches gh-150429, with follow-up fix in #150433. I pushed an empty commit to retrigger CI on the current PR head.

Copy link
Copy Markdown
Member

@savannahostrowski savannahostrowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this will still break with a proxy help string without a format specifier. The interpolation branch and the no-% branch in _expand_help reach re.sub by different routes, and only one of them is handled here. Let's add a test for this so we can catch it too.

Additionally, the summary and NEWS also overstate the scope of the change. This isn't fixing descriptions and epilogs and we don't need to since they weren't part of this regression (#142960 only changed the argument-help path). Please scope the wording down to what's actually fixed.

Please don't push empty commits to retrigger CI. It just creates additional noise. A comment stating that you don't think the failure is related is just fine.

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Jun 2, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@RaghunandanKumar RaghunandanKumar force-pushed the fix-argparse-string-like-help branch from 5915e36 to dc8b7d7 Compare June 3, 2026 00:05
@RaghunandanKumar
Copy link
Copy Markdown
Author

Addressed latest review feedback:

  • fixed string-like proxy handling for argument help without a % format specifier
  • kept scope limited to argument help only
  • narrowed NEWS wording to match actual fix scope

Testing:

  • ./python.exe -m test -v test_argparse -m test_argument_help_without_interpolation_accepts_string_like_proxy
  • ./python.exe -m test -v test_argparse -m test_argument_help_interpolation_accepts_string_like_proxy
  • ./python.exe -m test test_argparse

I have made the requested changes; please review again

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Jun 3, 2026

Thanks for making the requested changes!

@savannahostrowski: please review the changes made to this pull request.

@bedevere-app bedevere-app Bot requested a review from savannahostrowski June 3, 2026 00:13
@savannahostrowski
Copy link
Copy Markdown
Member

Alright, something about this issue had been nagging at me this afternoon, so I went back through the commit history again. I didn't realize this before but there's some asymmetry here between proxies with and without format specifiers. While proxies with a format specifier didn't raise before #142960, proxies without did, even with color off. As such, I think we should keep this PR minimally scoped to just resolving the immediate regression with proxies with format specifiers, and leave the discussion re. consistency for another issue/PR.

With that in mind, your commit dc8b7d7 was actually correct. The whole fix should just be the single str() coercion on the re.sub subject in _expand_help.

However, for next steps, I'd like to slow down a bit here. Instead of another revision, it would be helpful to hear your thoughts on the fix first. I would like to make sure that the changes landed are ones that work but are also ones you understand. We have a policy for this sort of thing in our devguide; please give our AI policy a read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting change review needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants