Skip to content

Bool ​

SUMMARY

A Boolean scalar value.

python
from telekinesis import datatypes
value = datatypes.Bool(True)
API Reference
Complete API documentation for Bool, including parameters, attributes, and methods.
View Reference →

Parameters ​

ParameterTypeDefaultDescription
databool | int | floatRequiredThe value to store, normalized to a Python bool via Python truthiness (matching bool(data)) — any nonzero int/float becomes True, 0/0.0 becomes False.

Raises ​

ExceptionCondition
TypeErrordata is not a bool, int, or float

Attributes ​

AttributeTypeDescription
databoolThe wrapped value. Since bool is immutable, no copying is ever required — reading data returns the normalized value directly. Assigning a new value re-validates it the same way as construction.

Methods ​

MethodTypeDescription
Bool.coerce(value, name="value")BoolConverts a bool, int, or float into a Bool, using the same truthiness normalization as the constructor (any nonzero value becomes True, zero becomes False). If value is already a Bool, it is returned unchanged. The optional name is only used to make validation error messages more descriptive.

Operators ​

OperationReturns
bool(x)Python bool
int(x)Python int (True → 1, False → 0)
x & yBool
x | yBool
x ^ yBool
~xBool
x == yPython bool
x != yPython bool

Logical operators accept Bool, bool, int, or float operands and normalize them using Python truthiness. Equality compares values rather than truthiness. For example, Bool(True) == 1 is True, while Bool(True) == 2 is False. Ordering operators (<, <=, >, >=) are not supported.

Visualization ​

python
import rerun as rr

# Your code block
# ....

rr.init("bool_example", spawn=True)
datatypes.visualize(value, entity_path="/value", label="Bool")

Example ​

python
"""Demonstrates the Telekinesis Bool datatype."""

import time

import rerun as rr
from loguru import logger

from telekinesis import datatypes

def bool_example():
    """Demonstrate creation, inspection, operations, visualization, and serialization."""

    # ======================= Create ============================================
    value = datatypes.Bool(True)
    logger.info(f"Created Bool: {value}")

    coerced = datatypes.Bool.coerce(1)
    logger.info(f"Bool coerced from int: {coerced}")

    # ======================= Inspect ===========================================
    logger.info(f"data={value.data}")

    # ======================= Operations ========================================
    value.data = False
    logger.info(f"Updated Bool: {value}")

    other = datatypes.Bool(True)

    logger.info(f"AND: {value} & {other} = {value & other}")
    logger.info(f"OR: {value} | {other} = {value | other}")
    logger.info(f"XOR: {value} ^ {other} = {value ^ other}")
    logger.info(f"NOT: ~{value} = {~value}")
    logger.info(f"Reflected AND: True & {value} = {True & value}")
    logger.info(f"Reflected OR: False | {value} = {False | value}")
    logger.info(f"Reflected XOR: True ^ {value} = {True ^ value}")
    logger.info(f"EQ: {value} == {other} = {value == other}")
    logger.info(f"int(value)={int(value)}")
    logger.info(f"bool(value)={bool(value)}")

    # ======================= Visualize =========================================
    rr.init("bool_example", spawn=True)
    datatypes.visualize(value, entity_path="/bool")

    # ======================= Serialize / Deserialize ===========================
    start = time.perf_counter()
    serialized = datatypes.serialize(value)
    serialization_ms = (time.perf_counter() - start) * 1000

    start = time.perf_counter()
    deserialized = datatypes.deserialize(serialized)["param_0"]
    deserialization_ms = (time.perf_counter() - start) * 1000

    logger.info(f"Deserialized Bool: {deserialized}")
    logger.info(f"Round-trip successful: {value == deserialized}")
    logger.info(f"Serialization time: {serialization_ms:.3f} ms")
    logger.info(f"Deserialization time: {deserialization_ms:.3f} ms")

if __name__ == "__main__":
    bool_example()