Since 0.30.0 having underscores in positional arguments with @arg decorator breaks argparse
The parameter get considered as an optional kwargs.
Poc with the error
from argh import arg, dispatch_command
@arg("foo_bar", help="fooooo")
def main(foo_bar):
return foo_bar
if __name__ == "__main__":
dispatch_command(main)
Error
Traceback (most recent call last):
File "/tmp/venv/lib/python3.11/site-packages/argh/assembling.py", line 361, in set_default_command
action = parser.add_argument(
^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/argparse.py", line 1436, in add_argument
kwargs = self._get_optional_kwargs(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/argparse.py", line 1571, in _get_optional_kwargs
raise ValueError(msg % args)
ValueError: invalid option string 'foo-bar': must start with a character '-'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/tmp/proof.py", line 8, in <module>
dispatch_command(main)
File "/tmp/venv/lib/python3.11/site-packages/argh/dispatching.py", line 401, in dispatch_command
set_default_command(parser, function)
File "/tmp/venv/lib/python3.11/site-packages/argh/assembling.py", line 367, in set_default_command
raise AssemblingError(
argh.exceptions.AssemblingError: main: cannot add 'foo_bar' as foo-bar/foo_bar: invalid option string 'foo-bar': must start with a character '-'
Since 0.30.0 having underscores in positional arguments with @arg decorator breaks argparse
The parameter get considered as an optional kwargs.
Poc with the error
Error
Without the decorator the error does not occur.