:orphan:

:mod:`cloup.constraints._conditional`
=====================================

.. py:module:: cloup.constraints._conditional

.. autoapi-nested-parse::

   This modules contains classes for creating conditional constraints.





                              
Classes
-------

.. autosummary::

   ~cloup.constraints._conditional.If

Functions
---------

.. autosummary::

   ~cloup.constraints._conditional.as_predicate


                                           
Contents
--------
.. py:function:: as_predicate(arg)


.. py:class:: If(condition, then, else_ = None)

   Bases: :py:obj:`cloup.constraints._core.Constraint`

   Checks one constraint or another depending on the truth value of the condition.

   .. versionadded:: 0.8.0
       you can now pass a sequence of parameter names as condition, which
       corresponds to the predicate ``AllSet(*param_names)``.

   :param condition:
       can be either an instance of ``Predicate`` or (more often) the name of a
       parameter or a list/tuple of parameters that must be all set for the
       condition to be true.
   :param then:
       a constraint checked if the condition is true.
   :param else_:
       an (optional) constraint checked if the condition is false.

   .. py:method:: help(ctx)

      A description of the constraint. 


   .. py:method:: check_consistency(params)

      Perform some sanity checks that detect inconsistencies between these
      constraints and the properties of the input parameters (e.g. required).

      For example, a constraint that requires the parameters to be mutually
      exclusive is not consistent with a group of parameters with multiple
      required options.

      These sanity checks are meant to catch developer's mistakes and don't
      depend on the values assigned to the parameters; therefore:

      - they can be performed before any parameter parsing
      - they can be disabled in production (setting
        ``check_constraints_consistency=False`` in ``context_settings``)

      :param params: list of :class:`click.Parameter` instances
      :raises: :exc:`~cloup.constraints.errors.UnsatisfiableConstraint`
               if the constraint cannot be satisfied independently from the values
               provided by the user


   .. py:method:: check_values(params, ctx)

      Check that the constraint is satisfied by the input parameters in the
      given context, which (among other things) contains the values assigned
      to the parameters in ``ctx.params``.

      You probably don't want to call this method directly.
      Use :meth:`check` instead.

      :param params: list of :class:`click.Parameter` instances
      :param ctx: :class:`click.Context`
      :raises:
          :exc:`~cloup.constraints.ConstraintViolated`


   .. py:method:: __repr__()

      Return repr(self).




                                         