We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Given the code
import argh @argh.arg("paths", nargs="*", default=["x", "z"]) def fun(paths:list[str]): print(paths) if __name__ == "__main__": argh.dispatch_command(fun)
> ./app.py ["x", "z"] # as expected - the value of 'default' > ./app.py a b [["a"], ["b"]] # Bug? I would expect ["a", "b"]
If I use argparse, it works fine
parser = argparse.ArgumentParser() parser.add_argument("paths", nargs="*", default=["x", "y"]) print(parser.parse_args([])) print(parser.parse_args(["a", "b"])) > Namespace(paths=['x', 'y']) > Namespace(paths=['a', 'b'])
If I don't specify the 'default' arg things work fine:
@argh.arg("paths", nargs="*") def with_argh(paths:list[str]): print(paths) > ./app.py a b ["a", "b"] Using latest 0.30.4
The text was updated successfully, but these errors were encountered:
fix: nargs + list as default value (#212)
cd6bbd2
Hi @pioio, thank you for the bug report!
Reproduced, confirmed, will be fixed in Argh v.0.30.5 (PR #213).
A workaround it to simply expect paths: list[str] | None and then do paths = paths or ["x", "y"].
paths: list[str] | None
paths = paths or ["x", "y"]
As a bonus I've added the assumption of nargs="*" based on a list default value, so you don't have to use the @arg decorator at all:
nargs="*"
list
@arg
def func(paths: list[str] = ["default-1", "default-2"]) -> None: print(paths) if __name__ == "__main__": parser = ArgumentParser() argh.set_default_command( parser, func, name_mapping_policy=argh.assembling.NameMappingPolicy.BY_NAME_IF_KWONLY ) argh.dispatch(parser)
The name mapping policy has to be explicitly specified until it becomes the default one in an upcoming version of Argh.
Sorry, something went wrong.
1d03e1b
No branches or pull requests
Given the code
If I use argparse, it works fine
If I don't specify the 'default' arg things work fine:
The text was updated successfully, but these errors were encountered: