Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-139946: distinguish stdout or stderr when colorizing output in argparse#140495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
Uh oh!
There was an error while loading. Please reload this page.
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 |
savannahostrowski commented Oct 27, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Thanks for addressing the comments. After thinking about this more, I'm a bit concerned about API compatibility. Adding the formatter parameter to Also, we'll need to add some tests here, since this wasn't caught with our existing test suite. |
hugovk commented Oct 28, 2025
After originally adding colour to argparse (#132323), we did get reports (#133653) that subclassing TypeError: HelpFormatter.__init__() got an unexpected keyword argument 'prefix_chars'We initially considered this a docs issue, because We could again consider this a docs issue, but I think we need to be careful about backwards compatibility especially after 3.14.0. Could be worth checking things like tox, virtualenv and mypy that were affected last time. And if we choose not to backport, we can still use ❯ NO_COLOR=1 ./python.exe -m calendar 2020 01 01 2> err ❯ # or ❯ PYTHON_COLORS=0 ./python.exe -m calendar 2020 01 01 2> err ❯ # then ❯ cat errusage: python.exe -m calendar [-h] [-w WIDTH] [-l LINES] [-s SPACING] [-m MONTHS] [-c CSS] [-L LOCALE] [-e ENCODING] [-t{text,html}] [-f FIRST_WEEKDAY] [year] [month]python.exe -m calendar: error: unrecognized arguments: 01 |
savannahostrowski commented Oct 30, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@hugovk Oh thanks, I missed that thread...this is the kind of thing I was afraid of. I'm inclined to say 3.15 onward + a docs update to note this limitation/workaround in 3.14. |
Uh oh!
There was an error while loading. Please reload this page.
fe5c9d7 to 82e00f0Comparesavannahostrowski commented Dec 4, 2025
Circling back on this (appreciate your patience @frostming!), based on this convo, I think we should just move forward with this for 3.15, no backport since this is an API change. For 3.14, we should open a separate PR for the documentation changes for the workaround. I'll leave this open for another couple days to see if anyone else wants to chime in. Otherwise, will merge 😄 ! |
savannahostrowski commented Dec 7, 2025
@frostming Mind resolving the merge conflicts and then I can get to merging this? 🙂 |
Signed-off-by: Frost Ming <[email protected]>
…olor Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
dc33ac5 to 8518870Comparefrostming commented Dec 8, 2025
It's done. Thank you very much. |
7099af8 into python:mainUh oh!
There was an error while loading. Please reload this page.
mpkocher commented Dec 9, 2025
Perhaps this is the best one can do with the current constraints and large usage of people using internal APIs.
There's just so much widespread use of internal APIs. The pattern is this: formatter=parser._get_formatter() # ...parser._print_message(formatter.format_help(), sys.stderr)General Search: https://github.com/search?q=language%3Apython+._get_formatter%28%29&type=code |
Fix issue: