Skip to content

Commit 666dd43

Browse files
Use formatter class to avoid premature colorization of prog
1 parent 98b78b6 commit 666dd43

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Lib/argparse.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,11 +1959,13 @@ def add_subparsers(self, **kwargs):
19591959
# prog defaults to the usage message of this parser, skipping
19601960
# optional arguments and with no "usage:" prefix
19611961
if kwargs.get('prog') is None:
1962-
formatter = self._get_formatter()
1962+
# Create formatter without color to avoid storing ANSI codes in prog
1963+
formatter = self.formatter_class(prog=self.prog)
1964+
formatter._set_color(False)
19631965
positionals = self._get_positional_actions()
19641966
groups = self._mutually_exclusive_groups
19651967
formatter.add_usage(None, positionals, groups, '')
1966-
kwargs['prog'] = formatter._decolor(formatter.format_help().strip())
1968+
kwargs['prog'] = formatter.format_help().strip()
19671969

19681970
# create the parsers action and add it to the positionals list
19691971
parsers_class = self._pop_action_class(kwargs, 'parsers')

0 commit comments

Comments
 (0)