Skip to content

Argparse print_help() and print_usage() do not color based on their file argument #156144

Description

@bulletmark

Bug report

Bug description:

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.

CPython versions tested on:

3.14

Operating systems tested on:

Arch Linux - up to date.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status
    Doc issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions