Skip to content

Cannot use parameterless command decorator with custom command_class #2416

@ewilliamson-patreon

Description

@ewilliamson-patreon

Click throws an assertion error if you try to use the parameterless command decorator on a group with a command_class defined. The error is due to the command_class being added to kwargs before the assertion for no kwargs.

minimal repro

import click

class CustomCommand(click.Command):
    pass

class CustomGroup(click.Group):
    command_class = CustomCommand

@click.group(cls=CustomGroup)
def grp():
    pass

@grp.command
def cli():
    click.echo("hello custom command class")

error

ewilliamson@ip-192-168-50-39 ~ % python minimal_repro.py
Traceback (most recent call last):
  File "/Users/ewilliamson/minimal_repro.py", line 14, in <module>
    def cli():
  File "/Users/ewilliamson/.pyenv/versions/3.10.7/lib/python3.10/site-packages/click/core.py", line 1847, in command
    assert (
AssertionError: Use 'command(**kwargs)(callable)' to provide arguments.

expected

The @grp.command would be successfully parsed the same as without using CustomGroup

Environment:

  • Python version: Python 3.10.7
  • Click version: click==8.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions