Skip to content

type_bridge.attribute.integer

integer

Integer attribute type for TypeDB.

Integer

Integer(value)

Bases: NumericAttribute

Integer attribute type that accepts int values.

Example

class Age(Integer): pass

class Count(Integer): pass

With Literal for type safety

class Priority(Integer): pass

priority: Literal[1, 2, 3] | Priority

Initialize Integer attribute with an integer value.

Parameters:

Name Type Description Default
value int

The integer value to store

required

Raises:

Type Description
ValueError

If value violates range_constraint

Source code in type_bridge/attribute/integer.py
def __init__(self, value: int):
    """Initialize Integer attribute with an integer value.

    Args:
        value: The integer value to store

    Raises:
        ValueError: If value violates range_constraint
    """
    int_value = int(value)

    # Check range constraint if defined on the class
    range_constraint = getattr(self.__class__, "range_constraint", None)
    if range_constraint is not None:
        range_min, range_max = range_constraint
        if range_min is not None:
            min_val = int(range_min)
            if int_value < min_val:
                raise ValueError(
                    f"{self.__class__.__name__} value {int_value} is below minimum {min_val}"
                )
        if range_max is not None:
            max_val = int(range_max)
            if int_value > max_val:
                raise ValueError(
                    f"{self.__class__.__name__} value {int_value} is above maximum {max_val}"
                )

    super().__init__(int_value)

value property

value

Get the stored integer value.

__int__

__int__()

Convert to int.

Source code in type_bridge/attribute/integer.py
def __int__(self) -> int:
    """Convert to int."""
    return int(self.value)