Giter Site home page Giter Site logo

Comments (4)

janluke avatar janluke commented on June 3, 2024

Did this cause an actual problem to you? If yes, I'd be interested in reading an example.

from cloup.

janluke avatar janluke commented on June 3, 2024

one can simply and happily copy/move them without resorting to setattr/getattr/delattr method.

I think I named it __constraints exactly to communicate that this is private API. But I think I'm okay with the change you're proposing. Do you want to open a PR?

from cloup.

pocek avatar pocek commented on June 3, 2024

Did this cause an actual problem to you? If yes, I'd be interested in reading an example.

Yes, it's a real problem I have encountered in a construct like this:

import cloup
from cloup.constraints import mutually_exclusive

class ClassBasedDecorator:
    def __init__(self, func):
        self.func = func

        # Standard attributes used by click
        self.__name__ = func.__name__
        self.__doc__ = func.__doc__

        if hasattr(func, '__click_params__'):
            self.__click_params__ = func.__click_params__
            del func.__click_params__

        # Cloup makes it harder
        if hasattr(func, '__constraints'):
            setattr(self, '__constraints',  getattr(func, '__constraints'))
            delattr(func, '__constraints')

    def __call__(self, *args, **kwargs):
        return self.func(*args, **kwargs)

@cloup.command(show_constraints=True)
@ClassBasedDecorator
@cloup.option('--foo')
@cloup.option('--bar')
@cloup.constraint(mutually_exclusive, ['foo', 'bar'])
def hello(foo, bar):
    """Hello"""
    print('hello')

hello()

I hope it doesn't look too unconventional - to have the decorators ordered like this, but this is the way that makes sense in my application.

Do you want to open a PR?

OK, I can to that.

from cloup.

janluke avatar janluke commented on June 3, 2024

Yes, it's a real problem I have encountered in a construct like this. [...] I hope it doesn't look too unconventional - to have the decorators ordered like this, but this is the way that makes sense in my application.

The construct was already clear but I was curious about the real use case which requires you to mess with __constraints. Anyway, it's fine, don't feel obliged to share the details. I'll wait for the PR :)

from cloup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.