Skip to content

Commit 4062e6c

Browse files
committed
fix: make _get_formatter to take file argument to avoid calling set_color
Signed-off-by: Frost Ming <[email protected]>
1 parent a7db074 commit 4062e6c

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Lib/argparse.py

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

2727-
def _get_formatter(self):
2727+
def _get_formatter(self, file=None):
27282728
formatter = self.formatter_class(prog=self.prog)
2729-
formatter._set_color(self.color)
2729+
formatter._set_color(self.color, file=file)
27302730
return formatter
27312731

27322732
# =====================
@@ -2736,15 +2736,13 @@ def _get_formatter(self):
27362736
def print_usage(self, file=None):
27372737
if file is None:
27382738
file = _sys.stdout
2739-
formatter = self._get_formatter()
2740-
formatter._set_color(self.color, file=file)
2739+
formatter = self._get_formatter(file=file)
27412740
self._print_message(self.format_usage(formatter=formatter), file)
27422741

27432742
def print_help(self, file=None):
27442743
if file is None:
27452744
file = _sys.stdout
2746-
formatter = self._get_formatter()
2747-
formatter._set_color(self.color, file=file)
2745+
formatter = self._get_formatter(file=file)
27482746
self._print_message(self.format_help(formatter=formatter), file)
27492747

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

0 commit comments

Comments
 (0)