Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Using argh.argh(args=... , default=...) causes double nesting of passed arguments #212

@pioio

Description

@pioio

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions