AutoBool

class baybe.utils.boolean.AutoBool[source]

Bases: Enum

Enum for representing Booleans whose values can be determined automatically.

Public methods

evaluate(predicate_function)

Evaluate the Boolean value under a given predicate function.

from_unstructured(value, /)

Create the enum member from unstructured input.

Public attributes and properties

TRUE

Represents the Boolean value True.

FALSE

Represents the Boolean value False.

AUTO

Indicates that the value of the Boolean should be determined automatically on-the-fly, using a predicate function.

evaluate(predicate_function: Callable[[], bool])[source]

Evaluate the Boolean value under a given predicate function.

Return type:

bool

classmethod from_unstructured(value: AutoBool | bool | str | None, /)[source]

Create the enum member from unstructured input.

For string inputs, see strtobool().

Parameters:

value (AutoBool | bool | str | None) – The (possibly unstructured) input value to be converted.

Return type:

AutoBool

Returns:

The corresponding enum member.

Raises:

ValueError – If the input cannot be converted to an enum member.

Example

>>> AutoBool.from_unstructured(AutoBool.TRUE)
<AutoBool.TRUE: 'TRUE'>
>>> AutoBool.from_unstructured(True)
<AutoBool.TRUE: 'TRUE'>
>>> AutoBool.from_unstructured("t")
<AutoBool.TRUE: 'TRUE'>
>>> AutoBool.from_unstructured(AutoBool.FALSE)
<AutoBool.FALSE: 'FALSE'>
>>> AutoBool.from_unstructured(False)
<AutoBool.FALSE: 'FALSE'>
>>> AutoBool.from_unstructured("f")
<AutoBool.FALSE: 'FALSE'>
>>> AutoBool.from_unstructured(AutoBool.AUTO)
<AutoBool.AUTO: 'AUTO'>
>>> AutoBool.from_unstructured(None)
<AutoBool.AUTO: 'AUTO'>
>>> AutoBool.from_unstructured("auto")
<AutoBool.AUTO: 'AUTO'>
AUTO = 'AUTO'

Indicates that the value of the Boolean should be determined automatically on-the-fly, using a predicate function.

FALSE = 'FALSE'

Represents the Boolean value False.

TRUE = 'TRUE'

Represents the Boolean value True.