cloup._util

Generic utilities.

Classes

FrozenSpaceMeta(*args)

FrozenSpace()

A class used just as frozen namespace for constants.

Functions

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[, default])

Returns the first value that is not None (or default if no such value exists).

listOfNotNone(iterable)

check_positive_int(value, arg_name)

identity(x)

pop_many(d, *keys)

Contents

cloup._util.click_version_tuple
cloup._util.T
cloup._util.class_name(obj)[source]
cloup._util.check_arg(condition, msg='')[source]
Parameters
  • condition (bool) –

  • msg (str) –

cloup._util.indent_lines(lines, width=2)[source]
Parameters

lines (Iterable[str]) –

Return type

List[str]

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

Generate repr(obj).

Parameters
  • obj – object to represent

  • args – 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 – keyword arguments in the repr

Returns

str

Return type

str

cloup._util.make_one_line_repr(obj, *args, **kwargs)[source]
cloup._util.pluralize(count, zero='', one='', many='')[source]
Parameters
  • count (int) –

  • zero (str) –

  • one (str) –

  • many (str) –

Return type

str

cloup._util.coalesce(*values, default=None)[source]

Returns the first value that is not None (or default if no such value exists). Inspired by the homonym SQL function.

Parameters

values (Optional[T]) –

Return type

Optional[T]

cloup._util.listOfNotNone(iterable)[source]
Parameters

iterable (Iterable[Optional[T]]) –

Return type

List[T]

cloup._util.check_positive_int(value, arg_name)[source]
cloup._util.identity(x)[source]
Parameters

x (T) –

Return type

T

class cloup._util.FrozenSpaceMeta(cls, *args)[source]

Bases: type

__setattr__(cls, key, value)[source]

Implement setattr(self, name, value).

asdict(cls)[source]
Return type

Dict[str, Any]

__contains__(cls, item)[source]
Parameters

item (str) –

Return type

bool

__getitem__(cls, item)[source]
class cloup._util.FrozenSpace[source]

A class used just as frozen namespace for constants.

cloup._util.pop_many(d, *keys)[source]
Parameters
Return type

dict