Skip to content

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

@serhiy-storchaka

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

Metadata

Metadata

Labels

3.14bugs and security fixes3.15new features, bugs 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