You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Argparse print_help() and print_usage() do not color based on their file argument #156144
Currently (in Python 3.14), both argparse.print_help() and argparse.print_usage() merely check whether stdout is eligible for coloring but both take a file argument and both should be checking against that instead of stdout. E.g. my app's stdout is attached to a file but I need sometimes to write my help/usage to the screen (e.g. via /dev/tty) and presently this is output without color although it can be (and looks much better!).
I made a very trivial patch to 3.14 argparse.py to fix this and was going to submit that as PR but there have been many recent changes to the same code so I decided just to raise this issue and attach my patch here.
No user or public facing API is changed so no documentation requires update.
Note also that no AI was used here, all implemented and tested by hand.
Thank you for ensure this! So this is already fixed on 3.15 (and main branch) by #140495 with original issue #139946, using a different approach compare to your patch.
That PR was not backported to 3.14 because it may break subclasses, see the discussion there.
Since this bug only means color is missing, and nothing is broken, I think fixing 3.14 with a different approach than main branch is not worth it, it adds maintenance cost and makes future backports harder. Leaving 3.14 as it is seems better to me.
Activity
bulletmark commentedon Aug 21, 2026
The trivial patch against Python 3.14 to fix this:
hugovk commentedon Aug 21, 2026
@bulletmark Please can you include a minimal, reproducible code example?
aisk commentedon Aug 21, 2026
And can you also try this issue on 3.15 or newer version, because I see #139946 may have some related changes.
bulletmark commentedon Aug 21, 2026
Just tried
3.15.0rc1and yes, it fixes this bug, for bothprint_help()andprint_usage().Do you still want me to create a minimal example, e.g. to back-fit my or other patch to fix 3.14?
aisk commentedon Aug 21, 2026
Thank you for ensure this! So this is already fixed on 3.15 (and main branch) by #140495 with original issue #139946, using a different approach compare to your patch.
That PR was not backported to 3.14 because it may break subclasses, see the discussion there.
Since this bug only means color is missing, and nothing is broken, I think fixing 3.14 with a different approach than main branch is not worth it, it adds maintenance cost and makes future backports harder. Leaving 3.14 as it is seems better to me.
picnixz commentedon Aug 21, 2026
Closing as
fixedin 3.15.0+ and won't fix for 3.14.bulletmark commentedon Aug 21, 2026
If anybody else comes along, I added the following to my application startup to address this issue: