From d66257f2c8cf9a9589d4767675024cadb51681be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 28 Feb 2023 20:26:20 +0100 Subject: [PATCH] improve option.Formatter performance as always, only a very marginal difference, but it still uses less resources than before --- gallery_dl/option.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/gallery_dl/option.py b/gallery_dl/option.py index af70c840..6ac58945 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -61,18 +61,15 @@ class OptionAction(argparse.Action): class Formatter(argparse.HelpFormatter): """Custom HelpFormatter class to customize help output""" - def __init__(self, *args, **kwargs): - super().__init__(max_help_position=30, *args, **kwargs) + def __init__(self, prog): + argparse.HelpFormatter.__init__(self, prog, max_help_position=30) - def _format_action_invocation(self, action): - opts = action.option_strings[:] - if opts: - if action.nargs != 0: - args_string = self._format_args(action, "ARG") - opts[-1] += " " + args_string - return ', '.join(opts) - else: - return self._metavar_formatter(action, action.dest)(1)[0] + def _format_action_invocation(self, action, join=", ".join): + opts = action.option_strings + if action.metavar: + opts = opts.copy() + opts[-1] += " " + action.metavar + return join(opts) def _parse_option(opt):