Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# `cloup.constraints.common`

Useful functions used to implement constraints and predicates.

## Functions

`param_value_is_set`(param, value) | Define what it means for a parameter of a specific kind to be "set".
`get_param_name`(param) | Return the name of a parameter casted to `str`.
`get_params_whose_value_is_set`(params, values) | Filter `params`, returning only the parameters that have a value.
`get_required_params`(params) |
`get_param_label`(param) |
`join_param_labels`(params[, sep]) |
`join_with_and`(strings[, sep]) |
`format_param`(param) |
`format_param_list`(param_list[, indent]) |
`param_label_by_name`(ctx, name) |
`get_param_labels`(ctx, param_names) |
`param_value_by_name`(ctx, name) |

## Contents

cloup.constraints.common.param_value_is_set(param, value)

  Define what it means for a parameter of a specific kind to be “set”.

  All cases are obvious besides that of boolean options: - (common rule) if the value is `None`, the parameter is unset; - a parameter that takes multiple values is set if at least one argument is provided; - a boolean flag is set only if True; - a boolean option is set if not None, even if it’s False.

  Parameters:

    - param (Parameter)

    - value (Any)

  Return type:

    bool

cloup.constraints.common.get_param_name(param)

  Return the name of a parameter casted to `str`. Use this function to avoid typing errors in places where you expect a parameter having a name.

  Parameters:

    param (Parameter)

  Return type:

    str

cloup.constraints.common.get_params_whose_value_is_set(params, values)

  Filter `params`, returning only the parameters that have a value. Boolean flags are considered “set” if their value is `True`.

  Parameters:

    - params (Iterable[Parameter])

    - values (Dict[str, Any])

  Return type:

    List[Parameter]

cloup.constraints.common.get_required_params(params)
  Parameters:

    params (Iterable[Parameter])

  Return type:

    List[Parameter]

cloup.constraints.common.get_param_label(param)
  Parameters:

    param (Parameter)

  Return type:

    str

cloup.constraints.common.join_param_labels(params, sep=', ')
  Parameters:

    - params (Iterable[Parameter])

    - sep (str)

  Return type:

    str

cloup.constraints.common.join_with_and(strings, sep=', ')
  Parameters:

    - strings (Sequence[str])

    - sep (str)

  Return type:

    str

cloup.constraints.common.format_param(param)
  Parameters:

    param (Parameter)

  Return type:

    str

cloup.constraints.common.format_param_list(param_list, indent=2)
  Parameters:

    - param_list (Iterable[Parameter])

    - indent (int)

  Return type:

    str

cloup.constraints.common.param_label_by_name(ctx, name)
  Parameters:

    - ctx (Any)

    - name (str)

  Return type:

    str

cloup.constraints.common.get_param_labels(ctx, param_names)
  Parameters:

    - ctx (Any)

    - param_names (Iterable[str])

  Return type:

    List[str]

cloup.constraints.common.param_value_by_name(ctx, name)
  Parameters:

    - ctx (Context)

    - name (str)

  Return type:

    Any