Comments (4)
Did this cause an actual problem to you? If yes, I'd be interested in reading an example.
from cloup.
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.
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.
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)
- Allow `params` attribute in decorators HOT 3
- Help text and epilog text are not normalized when using click >= 8.1.0
- Rename `GroupedOption` to `Option` and keep it as an alias
- Support option groups and constraints in Group by removing `BaseCommand` and making `Group` inherit from `Command`
- Drop support to Python 3.6 and test for 3.10 HOT 1
- AnySet/AllSet throws AttributeError HOT 5
- Mypy fails in strict mode HOT 5
- `SectionMixin`: `super().__init__` should be called at the beginning of `__init__` HOT 5
- Minor language issue in documentation HOT 3
- Optional parenthesis for `@command` and `@option` HOT 5
- Require one constraint prevents subcommand help from working HOT 5
- Test for Python 3.11
- Pytest: replace deprecated `pytest.warns(None)` with something else
- Rename `sorted` attribute of `Section` to `is_sorted` to solve conflict with `Section.sorted` static method HOT 6
- Use ruff and a code formatter HOT 1
- mutually_exclusive constraint doesn't work with multiple flags with flag_value HOT 1
- Styling of aliases HOT 1
- Custom MultiCommands (with styling) HOT 3
- Over-highlighting of heading's extra space HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloup.