Skip to content

Multiple arguments with multiple values raises an error from Click #260

@erdnaxeli

Description

@erdnaxeli

Describe the bug

Hi, I tried to define two arguments as List[str], and I got an exception from Click.

To Reproduce

  • Create a file main.py with:
from typing import List
import typer

app = typer.Typer()

@app.command()
def hello(name: List[str], other: List[str]):
    typer.echo(f"Hello {name}")


if __name__ == "__main__":
    app()
  • Call it with:
python main.py Camila
  • It outputs:
Traceback (most recent call last):
  File "/home/erdnaxeli/t.py", line 12, in <module>
    typer.run(create)
  File "/home/erdnaxeli/.pyenv/versions/3.6.7/lib/python3.6/site-packages/typer/main.py", line 859, in run
    app()
  File "/home/erdnaxeli/.pyenv/versions/3.6.7/lib/python3.6/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
  File "/home/erdnaxeli/.pyenv/versions/3.6.7/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/erdnaxeli/.pyenv/versions/3.6.7/lib/python3.6/site-packages/click/core.py", line 781, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/home/erdnaxeli/.pyenv/versions/3.6.7/lib/python3.6/site-packages/click/core.py", line 700, in make_context
    self.parse_args(ctx, args)
  File "/home/erdnaxeli/.pyenv/versions/3.6.7/lib/python3.6/site-packages/click/core.py", line 1045, in parse_args
    opts, args, param_order = parser.parse_args(args=args)
  File "/home/erdnaxeli/.pyenv/versions/3.6.7/lib/python3.6/site-packages/click/parser.py", line 270, in parse_args
    self._process_args_for_args(state)
  File "/home/erdnaxeli/.pyenv/versions/3.6.7/lib/python3.6/site-packages/click/parser.py", line 278, in _process_args_for_args
    state.largs + state.rargs, [x.nargs for x in self._args]
  File "/home/erdnaxeli/.pyenv/versions/3.6.7/lib/python3.6/site-packages/click/parser.py", line 67, in _unpack_args
    raise TypeError("Cannot have two nargs < 0")
TypeError: Cannot have two nargs < 0

Expected behavior

I know wat I am doing cannot work, but I expect either:

  • an undefined behavior (like always having an error about missing argument other because name swallow all parameters)
  • or an explicte error from typer

The error from Click is not very explicit.

  • OS: Linux
  • Typer Version: 0.3.2
  • Python version: 3.6.7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions