Skip to content

Option instance reuse with custom cls impossible #926

@simonpercivall

Description

@simonpercivall

Let's say I pre-define an option meant for multiple commands:

opt = click.option('opt', cls=CustomOption)

@opt
def cmd1(opt):
    pass


@opt
def cmd2(opt):
    pass

This will (click 6.7, and latest master when this issue was created) cause the cls parameter to be popped from **attrs – which is shared between all calls of the inner decorator, because of the closure – in the first call, leading to a broken option in the second call.

Of course, it's possible to work around this by instead defining a function that returns the option, but it would be nice to just fix the decorators by copying attrs before popping cls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions