-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
MWE
from dataclasses import dataclass
import defopt
def main(
args: list[str],
):
pass
def ok(
*args: str,
):
pass
@dataclass
class Main:
args: list[str]
@dataclass
class Ok:
arg: str
if __name__ == "__main__":
defopt.run(
(main, ok, Main, Ok),
strict_kwonly=False,
)resulted in
❯ python example.py ok -h
usage: example.py ok [-h] [args ...]
positional arguments:
args
optional arguments:
-h, --help show this help message and exit
❯ python example.py main -h
usage: example.py main [-h] -a [ARGS ...]
optional arguments:
-h, --help show this help message and exit
-a [ARGS ...], --args [ARGS ...]
❯ python example.py Main -h
usage: example.py Main [-h] -a [ARGS ...]
Main(args: list)
optional arguments:
-h, --help show this help message and exit
-a [ARGS ...], --args [ARGS ...]
❯ python example.py Ok -h
usage: example.py Ok [-h] arg
Ok(arg: str)
positional arguments:
arg
optional arguments:
-h, --help show this help message and exitNotes
The feature request is to support main(args: list[TypeX], *, ...) to be equivalent in terms of defopt to main(*args: TypeX, ...).
In the function case, main, the user could have written it as the function ok instead.
In the dataclass case however, since Python's dataclass doesn't support variable positional arguments, one cannot defines *args. So the only sensible choice here is to define args: list instead.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels