Skip to content

Option instance reuse with custom cls impossible #926

Closed

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.

Activity

  1. ulope commented on Apr 19, 2018

    @ulope
    Contributor

    Indeed, this is very surprising.

  2. added a commit that references this issue on May 14, 2018
  3. fdavis commented on May 17, 2018

    @fdavis
    Contributor

    Resolved by #994 please reopen if you still experience this issue in master

  4. added this to the 7.0 milestone on Sep 10, 2018
  5. added 2 commits that reference this issue on Oct 8, 2018
  6. added a commit that references this issue on Oct 29, 2018
  7. locked as resolved and limited conversation to collaborators on Nov 13, 2020
  8. added
    parsing
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    parsing

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions