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

# `cloup._util`

Generic utilities.

## Classes

`FrozenSpaceMeta`(*args) |
`FrozenSpace`() | A class used just as frozen namespace for constants.

## Functions

`pick_non_missing`(d) |
`class_name`(obj) |
`check_arg`(condition[, msg]) |
`indent_lines`(lines[, width]) |
`make_repr`(obj, *args[, _line_len, _indent]) | Generate repr(obj).
`make_one_line_repr`(obj, *args, **kwargs) |
`pluralize`(count[, zero, one, many]) |
`coalesce`(*values) | Return the first value that is not `None` (or `None` if no such value exists).
`first_bool`(*values) | Return the first bool (or raises `StopIteration` if no bool is found).
`pick_not_none`(iterable) |
`check_positive_int`(value, arg_name) |
`identity`(x) |
`delete_keys`(d, keys) |
`reindent`(text[, indent]) |

## Attributes

`click_version_tuple` |
`click_major` |
`click_minor` |
`click_version_ge_8_1` |
`T` |
`K` |
`V` |

## Contents

cloup._util.click_version_tuple

cloup._util.click_major

cloup._util.click_minor

cloup._util.click_version_ge_8_1

cloup._util.T

cloup._util.K

cloup._util.V

cloup._util.pick_non_missing(d)
  Parameters:

    d (Dict[K, _Missing | V]) –

  Return type:

    Dict[K, V]

cloup._util.class_name(obj)
  Parameters:

    obj (object) –

  Return type:

    str

cloup._util.check_arg(condition, msg='')
  Parameters:

    - condition (bool) –

    - msg (str) –

  Return type:

    None

cloup._util.indent_lines(lines, width=2)
  Parameters:

    - lines (Iterable[str]) –

    - width (int) –

  Return type:

    List[str]

cloup._util.make_repr(obj, *args, _line_len=60, _indent=2, **kwargs)

  Generate repr(obj).

  Parameters:

    - obj (Any) – object to represent

    - args (Any) – positional arguments in the repr

    - _line_len (int) – if the repr length exceeds this, arguments will be on their own line; if negative, the repr will be in a single line regardless of its length

    - _indent (int) – indentation width of arguments in case they are shown in their own line

    - kwargs (Any) – keyword arguments in the repr

  Returns:

    str

  Return type:

    str

cloup._util.make_one_line_repr(obj, *args, **kwargs)
  Parameters:

    - obj (object) –

    - args (Any) –

    - kwargs (Any) –

  Return type:

    str

cloup._util.pluralize(count, zero='', one='', many='')
  Parameters:

    - count (int) –

    - zero (str) –

    - one (str) –

    - many (str) –

  Return type:

    str

cloup._util.coalesce(*values)

  Return the first value that is not `None` (or `None` if no such value exists).

  Parameters:

    values (T | None) –

  Return type:

    T | None

cloup._util.first_bool(*values)

  Return the first bool (or raises `StopIteration` if no bool is found).

  Parameters:

    values (Any) –

  Return type:

    bool

cloup._util.pick_not_none(iterable)
  Parameters:

    iterable (Iterable[T | None]) –

  Return type:

    List[T]

cloup._util.check_positive_int(value, arg_name)
  Parameters:

    - value (Any) –

    - arg_name (str) –

  Return type:

    None

cloup._util.identity(x)
  Parameters:

    x (T) –

  Return type:

    T

class cloup._util.FrozenSpaceMeta(*args)

  Bases: `type`

  Parameters:

    args (Any) –

  __setattr__(key, value)

    Implement setattr(self, name, value).

    Parameters:

      - key (str) –

      - value (Any) –

    Return type:

      None

  asdict()
    Return type:

      Dict[str, Any]

  __contains__(item)
    Parameters:

      item (str) –

    Return type:

      bool

  __getitem__(item)
    Parameters:

      item (str) –

    Return type:

      Any

class cloup._util.FrozenSpace

  A class used just as frozen namespace for constants.

cloup._util.delete_keys(d, keys)
  Parameters:

    - d (Dict[Any, Any]) –

    - keys (Sequence[str]) –

  Return type:

    None

cloup._util.reindent(text, indent=0)
  Parameters:

    - text (str) –

    - indent (int) –

  Return type:

    str