Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# `cloup.constraints.conditions`

This modules contains predicates with an associated description 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

`Predicate`() | A `Callable` that takes a `click.Context` and returns a boolean, with an associated description.
`Not`(predicate) | Logical NOT of a predicate.
`IsSet`(param_name) | True if the parameter is set.
`AllSet`(*param_names) | True if all listed parameters are set.
`AnySet`(*param_names) | True if any of the listed parameters is set.
`Equal`(param_name, value) | True if the parameter value equals `value`.

## Attributes

`P` |

## Contents

cloup.constraints.conditions.P

class cloup.constraints.conditions.Predicate

  Bases: `abc.ABC`

  A `Callable` that takes a `click.Context` and returns a boolean, with an associated description. Meant to be used as condition in a conditional constraint (see `If`).

  abstract description(ctx)

    Succinct description of the predicate (alias: desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  negated_description(ctx)

    Succinct description of the negation of this predicate (alias: neg_desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  desc(ctx)

    Short alias for `description()`.

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  neg_desc(ctx)

    Short alias for `negated_description()`.

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  negated()
    Return type:

      Predicate

  abstract __call__(ctx)

    Evaluate the predicate on the given context.

    Parameters:

      ctx (click.Context) –

    Return type:

      bool

  __invert__()
    Return type:

      Predicate

  __or__(other)
    Parameters:

      other (Predicate) –

    Return type:

      Predicate

  __and__(other)
    Parameters:

      other (Predicate) –

    Return type:

      Predicate

  __repr__()

    Return repr(self).

    Return type:

      str

  __eq__(other)

    Return self==value.

    Parameters:

      other (object) –

    Return type:

      bool

class cloup.constraints.conditions.Not(predicate)

  Bases: `Predicate`, `Generic`[`P`]

  Logical NOT of a predicate.

  Parameters:

    predicate (P) –

  description(ctx)

    Succinct description of the predicate (alias: desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  negated_description(ctx)

    Succinct description of the negation of this predicate (alias: neg_desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  __call__(ctx)

    Evaluate the predicate on the given context.

    Parameters:

      ctx (click.Context) –

    Return type:

      bool

  __invert__()
    Return type:

      P

  __repr__()

    Return repr(self).

    Return type:

      str

class cloup.constraints.conditions.IsSet(param_name)

  Bases: `Predicate`

  True if the parameter is set.

  Parameters:

    param_name (str) –

  description(ctx)

    Succinct description of the predicate (alias: desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  negated_description(ctx)

    Succinct description of the negation of this predicate (alias: neg_desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  __call__(ctx)

    Evaluate the predicate on the given context.

    Parameters:

      ctx (click.Context) –

    Return type:

      bool

  __and__(other)
    Parameters:

      other (Predicate) –

    Return type:

      Predicate

  __or__(other)
    Parameters:

      other (Predicate) –

    Return type:

      Predicate

class cloup.constraints.conditions.AllSet(*param_names)

  Bases: `Predicate`

  True if all listed parameters are set.

  New in version 0.8.0.

  Parameters:

    param_names (str) –

  negated_description(ctx)

    Succinct description of the negation of this predicate (alias: neg_desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  description(ctx)

    Succinct description of the predicate (alias: desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  __call__(ctx)

    Evaluate the predicate on the given context.

    Parameters:

      ctx (click.Context) –

    Return type:

      bool

  __and__(other)
    Parameters:

      other (Predicate) –

    Return type:

      Predicate

class cloup.constraints.conditions.AnySet(*param_names)

  Bases: `Predicate`

  True if any of the listed parameters is set.

  New in version 0.8.0.

  Parameters:

    param_names (str) –

  negated_description(ctx)

    Succinct description of the negation of this predicate (alias: neg_desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  description(ctx)

    Succinct description of the predicate (alias: desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  __call__(ctx)

    Evaluate the predicate on the given context.

    Parameters:

      ctx (click.Context) –

    Return type:

      bool

  __or__(other)
    Parameters:

      other (Predicate) –

    Return type:

      Predicate

class cloup.constraints.conditions.Equal(param_name, value)

  Bases: `Predicate`

  True if the parameter value equals `value`.

  Parameters:

    - param_name (str) –

    - value (Any) –

  description(ctx)

    Succinct description of the predicate (alias: desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  negated_description(ctx)

    Succinct description of the negation of this predicate (alias: neg_desc).

    Parameters:

      ctx (click.Context) –

    Return type:

      str

  __call__(ctx)

    Evaluate the predicate on the given context.

    Parameters:

      ctx (click.Context) –

    Return type:

      bool