Bool
SUMMARY
A Boolean scalar value.
python
from telekinesis import datatypes
value = datatypes.Bool(True)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | bool | int | float | Required | The 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
| Exception | Condition |
|---|---|
TypeError | data is not a bool, int, or float |
Attributes
| Attribute | Type | Description |
|---|---|---|
data | bool | The 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
| Method | Type | Description |
|---|---|---|
Bool.coerce(value, name="value") | Bool | Converts 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
| Operation | Returns |
|---|---|
bool(x) | Python bool |
int(x) | Python int (True → 1, False → 0) |
x & y | Bool |
x | y | Bool |
x ^ y | Bool |
~x | Bool |
x == y | Python bool |
x != y | Python bool |
&/\|/^ (and their reflected forms, e.g. True & value) accept a Bool, bool, int, or float operand on either side, normalizing it via the same truthiness rule as construction — so value & 5 is valid and treats 5 as truthy. ==/!= compare by value rather than truthiness: Bool(True) == 1 is True, but Bool(True) == 2 is False even though 2 is truthy. Bool has no ordering support — <, <=, >, >= are not implemented.
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()