From: Frantisek Sumsal Date: Fri, 5 Mar 2021 12:06:12 +0000 (+0100) Subject: Pass the list of choices to argparse.Action X-Git-Tag: v10~55^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F671%2Fhead;p=thirdparty%2Fmkosi.git Pass the list of choices to argparse.Action This way our custom ListAction action can properly generate a list of choices in the help message when the metavar is not defined: Before: $ mkosi --help ... --debug SELECTOR Turn on debugging output After: $ mkosi --help ... --debug {run,build-script,workspace-command} Turn on debugging output --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 0baba05fb..dd7e4ad2d 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -4250,7 +4250,9 @@ class ListAction(argparse.Action): def __init__(self, *args: Any, choices: Optional[Iterable[Any]] = None, **kwargs: Any) -> None: self.list_choices = choices - super().__init__(*args, **kwargs) + # mypy doesn't like the following call due to https://github.com/python/mypy/issues/6799, + # so let's, temporarily, ignore the error + super().__init__(choices=choices, *args, **kwargs) # type: ignore[misc] def __call__( self, # These type-hints are copied from argparse.pyi @@ -4815,7 +4817,6 @@ def create_parser() -> ArgumentParserMkosi: action=CommaDelimitedListAction, default=[], help="Turn on debugging output", - metavar="SELECTOR", choices=("run", "build-script", "workspace-command"), ) try: