Skip to content

Commit 6c02905

Browse files
committed
fix: make _get_formatter to take file argument to avoid calling set_color
Signed-off-by: Frost Ming <me@frostming.com>
1 parent 6d10257 commit 6c02905

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

Lib/argparse.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,9 +2748,9 @@ def format_help(self, formatter=None):
27482748
# determine help from format above
27492749
return formatter.format_help()
27502750

2751-
def _get_formatter(self):
2751+
def _get_formatter(self, file=None):
27522752
formatter = self.formatter_class(prog=self.prog)
2753-
formatter._set_color(self.color)
2753+
formatter._set_color(self.color, file=file)
27542754
return formatter
27552755

27562756
def _get_validation_formatter(self):
@@ -2767,15 +2767,13 @@ def _get_validation_formatter(self):
27672767
def print_usage(self, file=None):
27682768
if file is None:
27692769
file = _sys.stdout
2770-
formatter = self._get_formatter()
2771-
formatter._set_color(self.color, file=file)
2770+
formatter = self._get_formatter(file=file)
27722771
self._print_message(self.format_usage(formatter=formatter), file)
27732772

27742773
def print_help(self, file=None):
27752774
if file is None:
27762775
file = _sys.stdout
2777-
formatter = self._get_formatter()
2778-
formatter._set_color(self.color, file=file)
2776+
formatter = self._get_formatter(file=file)
27792777
self._print_message(self.format_help(formatter=formatter), file)
27802778

27812779
def _print_message(self, message, file=None):

0 commit comments

Comments
 (0)