Skip to content

Raise clear error for multiple variadic arguments#1555

Open
worksbyfriday wants to merge 1 commit into
fastapi:masterfrom
worksbyfriday:fix-multiple-list-args-260
Open

Raise clear error for multiple variadic arguments#1555
worksbyfriday wants to merge 1 commit into
fastapi:masterfrom
worksbyfriday:fix-multiple-list-args-260

Conversation

@worksbyfriday
Copy link
Copy Markdown

Summary

Closes #260.

When a command has more than one argument annotated with List[...] (or any type that maps to nargs=-1), Click raises an opaque TypeError: Cannot have two nargs < 0. This PR adds early validation in Typer's parameter collection to detect multiple variadic arguments and raise a clear UsageError explaining the constraint.

Changes

  • Added validation after parameter collection in get_params_convertors_ctx_param_name_from_function() to check for multiple arguments with nargs < 0
  • Raises click.UsageError with a message naming all conflicting arguments
  • Added test test_multiple_list_arguments_error in tests/test_type_conversion.py

Example

Before:

TypeError: Cannot have two nargs < 0

After:

UsageError: Only one argument can take multiple values (nargs=-1), but 2 were found: 'names', 'others'. Use List[...] (or Sequence[...]) for at most one argument.

When a command has more than one argument annotated with List[...],
Click raises an opaque "TypeError: Cannot have two nargs < 0".
This adds validation in Typer's parameter collection to detect
multiple variadic arguments early and raise a clear UsageError
explaining the constraint.

Closes fastapi#260
@svlandeg svlandeg added the feature New feature, enhancement or request label Mar 16, 2026
@github-actions github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label May 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically generated when a PR has a merge conflict feature New feature, enhancement or request waiting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple arguments with multiple values raises an error from Click

3 participants