GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 3.14+ argparse colorization makes sub-commands prog always colored if colored at creation time · Issue #139809 · python/cpython

3.14+ argparse colorization makes sub-commands prog always colored if colored at creation time #139809

New issue
Copy link
New issue
Copy link
Closed
Closed
3.14+ argparse colorization makes sub-commands prog always colored if colored at creation time#139809
Copy link
Assignees
savannahostrowski
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@gaborbernat
gaborbernat
opened on Oct 8, 2025
Issue body actions

Bug report

Bug description:

Here's an example script that replicates the problem:

from __future__ import annotations

import os
from argparse import ArgumentParser
from contextlib import suppress
from unittest.mock import patch

os.environ["FORCE_COLOR"] = "1"

parser = ArgumentParser(description="argparse tester", prog="complex")
parser.add_argument("--root", action="store_true", help="root flag")
sub = parser.add_subparsers(dest="command")
sub.add_parser("demo")

with suppress(SystemExit):
    parser.parse_args(["demo", "--help"])

with patch.dict(os.environ, {"NO_COLOR": "1"}, clear=False):
    parser.parse_args(["demo", "--help"])

You can see the first invocation prints everything in color, while the second only the sub-command:

Image

This is because https://github.com/python/cpython/blame/main/Lib/argparse.py#L1966 passes through the prog formatted and not as raw. This example is contrived a bit to have a minimal demonstration, the actual issue I'm facing is in https://github.com/tox-dev/sphinx-argparse-cli where I'm reading this value directly to generate Sphinx documentation from this.

CPython versions tested on:

3.14, 3.15

Operating systems tested on:

Linux, macOS

Linked PRs

  • GH-139809: Fix argparse subcommand prog not respecting color environment variables #139818
  • [3.14] GH-139809: Fix argparse subcommand prog not respecting color environment variables (GH-139818) #139866

Activity

  1. gaborbernat
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 8, 2025
  2. savannahostrowski
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Oct 8, 2025
  3. savannahostrowski
    self-assigned this
    on Oct 8, 2025
  4. StanFromIreland
    added this to Argparse issueson Oct 8, 2025
  5. mpkocher commented on Oct 8, 2025

    @mpkocher
    mpkocher
    on Oct 8, 2025
    Contributor
    More actions

    As an aside, you can use parser = ArgumentParser(description="argparse tester", prog="complex", exit_on_error=False) to make testing easier.

    >>> from argparse import ArgumentParser
    >>> parser = ArgumentParser(description="argparse tester", prog="complex", exit_on_error=False)
    >>> parser.parse_args(['dragons'])
    Traceback (most recent call last):
      File "<python-input-2>", line 1, in <module>
        parser.parse_args(['dragons'])
        ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
    (snip...)
        raise ArgumentError(None, msg)
    argparse.ArgumentError: unrecognized arguments: dragons
    >>>
  6. savannahostrowski
    added
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    on Oct 8, 2025
  7. savannahostrowski commented on Oct 9, 2025

    @savannahostrowski
    savannahostrowski
    on Oct 9, 2025
    Member
    More actions

    Hey - thanks for filing this. Looks like we missed applying _decolor here when we landed in #132323. I've opened a PR to fix this.

  8. savannahostrowski
    added a commit that references this issue on Oct 9, 2025

    GH-139809: Fix argparse subcommand prog not respecting color environm…

    9fc4366
  9. miss-islington
    added a commit that references this issue on Oct 9, 2025

    pythonGH-139809: Fix argparse subcommand prog not respecting color en…

    c898f24
  10. savannahostrowski
    added a commit that references this issue on Oct 9, 2025

    [3.14] GH-139809: Fix argparse subcommand prog not respecting color e…

    af1cb1c
  11. savannahostrowski
    closed this as completedon Oct 9, 2025
  12. github-project-automation
    moved this to Doc issues in Argparse issueson Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @savannahostrowski
    savannahostrowski

Labels

3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

  • Argparse issues
    Status
    Doc issues
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.