Skip to content

Types

Pactole Index / Utils / Types

Auto-generated documentation for utils.types module.

assert_non_negative_integer

Show source in types.py:54

Assert that a value is a non-negative integer.

Arguments

  • value - The value to check.
  • name - The name of the value for error messages. Defaults to "value".

Raises

  • ValueError - If the value is not a non-negative integer.

Examples

>>> assert_non_negative_integer(5)
>>> assert_non_negative_integer(-1)
Traceback (most recent call last):
    ...
ValueError: value must be a non-negative integer, got -1

Signature

def assert_non_negative_integer(value: int, name: str = "value") -> None: ...

get_float

Show source in types.py:28

Convert a value to a float, if possible.

Arguments

  • value - The value to convert.
  • default - The default value to return if conversion fails. Defaults to 0.0.

Returns

  • float - The converted float value, or the default if conversion fails.

Examples

>>> get_float("3.14")
3.14
>>> get_float("abc", default=1.0)
1.0
>>> get_float(None, default=2.5)
2.5

Signature

def get_float(value, default: float = 0.0) -> float: ...

get_int

Show source in types.py:4

Convert a value to an integer, if possible.

Arguments

  • value - The value to convert.
  • default - The default value to return if conversion fails. Defaults to 0.

Returns

  • int - The converted integer value, or the default if conversion fails.

Examples

>>> get_int("42")
42
>>> get_int("abc", default=10)
10
>>> get_int(None, default=5)
5

Signature

def get_int(value, default: int = 0) -> int: ...