Closed pioio closed 8 months ago
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"]
.
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:
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.
Given the code
If I use argparse, it works fine
If I don't specify the 'default' arg things work fine: