cloup.constraints.conditions
¶
This modules contains described predicates that you can use as conditions of
conditional constraints (see cloup.constraints.If
).
Predicates should be treated as immutable objects, even though immutability is not (at the moment) enforced.
Classes summary¶
A |
|
|
|
|
True if the parameter is set. |
True if the parameter value equals |
Contents¶
-
cloup.constraints.conditions.
P
¶
-
class
cloup.constraints.conditions.
Predicate
[source]¶ Bases:
abc.ABC
A
Callable
that takes aContext
and returns a boolean, with an associated description. Meant to be used as condition in a conditional constraint (seeIf
).-
abstract
description
(self, ctx: click.Context) → str[source]¶ Succint description of the predicate (alias: desc).
-
negated_description
(self, ctx: click.Context) → str[source]¶ Succint description of the negation of this predicate (alias: neg_desc).
-
desc
(self, ctx: click.Context) → str[source]¶ Short alias for
description()
.
-
neg_desc
(self, ctx: click.Context) → str[source]¶ Short alias for
negated_description()
.
-
abstract
__call__
(self, ctx: click.Context) → bool[source]¶ Evaluate the predicate on the given context.
-
__invert__
(self) → cloup.constraints.conditions.Predicate[source]¶
-
__or__
(self, other: cloup.constraints.conditions.Predicate) → cloup.constraints.conditions._Or[source]¶
-
__and__
(self, other: cloup.constraints.conditions.Predicate) → cloup.constraints.conditions._And[source]¶
-
abstract
-
class
cloup.constraints.conditions.
Not
(predicate: P)[source]¶ Bases:
cloup.constraints.conditions.Predicate
,Generic[P]
A
Callable
that takes aContext
and returns a boolean, with an associated description. Meant to be used as condition in a conditional constraint (seeIf
).-
description
(self, ctx: click.Context) → str[source]¶ Succint description of the predicate (alias: desc).
-
negated_description
(self, ctx: click.Context) → str[source]¶ Succint description of the negation of this predicate (alias: neg_desc).
-
__call__
(self, ctx: click.Context) → bool[source]¶ Evaluate the predicate on the given context.
-
-
class
cloup.constraints.conditions.
IsSet
(param_name: str)[source]¶ Bases:
cloup.constraints.conditions.Predicate
A
Callable
that takes aContext
and returns a boolean, with an associated description. Meant to be used as condition in a conditional constraint (seeIf
).- Parameters
param_name (str) –
-
description
(self, ctx: click.Context) → str[source]¶ Succint description of the predicate (alias: desc).
-
negated_description
(self, ctx: click.Context) → str[source]¶ Succint description of the negation of this predicate (alias: neg_desc).
-
__call__
(self, ctx: click.Context) → bool[source]¶ Evaluate the predicate on the given context.
-
class
cloup.constraints.conditions.
Equal
(param_name: str, value: Any)[source]¶ Bases:
cloup.constraints.conditions.Predicate
True if the parameter value equals
value
.- Parameters
param_name (str) –
value (Any) –
-
description
(self, ctx: click.Context) → str[source]¶ Succint description of the predicate (alias: desc).
-
negated_description
(self, ctx: click.Context) → str[source]¶ Succint description of the negation of this predicate (alias: neg_desc).
-
__call__
(self, ctx: click.Context) → bool[source]¶ Evaluate the predicate on the given context.