gigl.common.utils.parse#

Functions#

str_to_bool(value)

Converts a string representation of truth to a bool.

Module Contents#

gigl.common.utils.parse.str_to_bool(value)[source]#

Converts a string representation of truth to a bool.

Accepts and rejects the same spellings as distutils.util.strtobool, which Python 3.12 removes from the standard library, though the ValueError message keeps the caller’s casing instead of lowercasing it:

  • True: “y”, “yes”, “t”, “true”, “on”, “1”

  • False: “n”, “no”, “f”, “false”, “off”, “0”

Matching is case-insensitive. Whitespace is not stripped, so “ true” raises rather than returning True.

Example

>>> str_to_bool("TRUE")
True
>>> str_to_bool("off")
False
Parameters:

value (str) – The string to interpret as a boolean.

Returns:

The truth value value spells.

Return type:

bool

Raises:

ValueError – If value is not one of the accepted spellings.