Skip to content

argparse does not strip the outer [] in a group in color mode #142332

Closed

Description

@serhiy-storchaka

Bug report

Without color, argparse strips the outer [] in a group. But it is not stripped with color.

The following example:

import argparse

parser = argparse.ArgumentParser(color=False, prog="PROG")
group = parser.add_mutually_exclusive_group()
group.add_argument('--foo', action='store_true', help='FOO')
group.add_argument('--spam', help='SPAM')
group.add_argument('badger', nargs='*', help='BADGER')
print(parser.format_usage())

parser = argparse.ArgumentParser(color=True, prog="PROG")
group = parser.add_mutually_exclusive_group()
group.add_argument('--foo', action='store_true', help='FOO')
group.add_argument('--spam', help='SPAM')
group.add_argument('badger', nargs='*', help='BADGER')
print(parser.format_usage())

outputs:

usage: PROG [-h] [--foo | --spam SPAM | badger ...]

usage: PROG [-h] [--foo | --spam SPAM | [badger ...]]

(the latter line in color).

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    3.14bugs and security fixes
    on Dec 6, 2025
  2. added 2 commits that reference this issue on Dec 6, 2025
  3. added a commit that references this issue on Dec 6, 2025
  4. added a commit that references this issue on Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

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

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions