Skip to content

type_bridge.attribute.numeric

numeric

Numeric attribute base class with shared arithmetic operators.

NumericAttribute

NumericAttribute(value=None)

Bases: Attribute

Base class for numeric attribute types with arithmetic operators.

This provides shared implementation for arithmetic operations that Integer, Double, and Decimal can inherit.

Subclasses must implement: - _accepted_types: tuple of Python types accepted for operations - _coerce_value: convert raw value to the appropriate type - init: initialize with type-specific value handling

Source code in type_bridge/attribute/base.py
@abstractmethod
def __init__(self, value: Any = None):
    """Initialize attribute with a value.

    Args:
        value: The value to store in this attribute instance
    """
    self._value = value

__add__

__add__(other)

Add two numeric values.

Source code in type_bridge/attribute/numeric.py
def __add__(self, other: object) -> Self:
    """Add two numeric values."""
    other_val = self._get_operand_value(other)
    if other_val is not None:
        return self._create_result(self.value + other_val)
    return NotImplemented

__radd__

__radd__(other)

Right-hand add.

Source code in type_bridge/attribute/numeric.py
def __radd__(self, other: object) -> Self:
    """Right-hand add."""
    if isinstance(other, self._accepted_types):
        return self._create_result(other + self.value)
    return NotImplemented

__sub__

__sub__(other)

Subtract two numeric values.

Source code in type_bridge/attribute/numeric.py
def __sub__(self, other: object) -> Self:
    """Subtract two numeric values."""
    other_val = self._get_operand_value(other)
    if other_val is not None:
        return self._create_result(self.value - other_val)
    return NotImplemented

__rsub__

__rsub__(other)

Right-hand subtract.

Source code in type_bridge/attribute/numeric.py
def __rsub__(self, other: object) -> Self:
    """Right-hand subtract."""
    if isinstance(other, self._accepted_types):
        return self._create_result(other - self.value)
    return NotImplemented

__mul__

__mul__(other)

Multiply two numeric values.

Source code in type_bridge/attribute/numeric.py
def __mul__(self, other: object) -> Self:
    """Multiply two numeric values."""
    other_val = self._get_operand_value(other)
    if other_val is not None:
        return self._create_result(self.value * other_val)
    return NotImplemented

__rmul__

__rmul__(other)

Right-hand multiply.

Source code in type_bridge/attribute/numeric.py
def __rmul__(self, other: object) -> Self:
    """Right-hand multiply."""
    if isinstance(other, self._accepted_types):
        return self._create_result(other * self.value)
    return NotImplemented

__truediv__

__truediv__(other)

True division.

Source code in type_bridge/attribute/numeric.py
def __truediv__(self, other: object) -> Self:
    """True division."""
    other_val = self._get_operand_value(other)
    if other_val is not None:
        return self._create_result(self.value / other_val)
    return NotImplemented

__rtruediv__

__rtruediv__(other)

Right-hand true division.

Source code in type_bridge/attribute/numeric.py
def __rtruediv__(self, other: object) -> Self:
    """Right-hand true division."""
    if isinstance(other, self._accepted_types):
        return self._create_result(other / self.value)
    return NotImplemented

__floordiv__

__floordiv__(other)

Floor division.

Source code in type_bridge/attribute/numeric.py
def __floordiv__(self, other: object) -> Self:
    """Floor division."""
    other_val = self._get_operand_value(other)
    if other_val is not None:
        return self._create_result(self.value // other_val)
    return NotImplemented

__rfloordiv__

__rfloordiv__(other)

Right-hand floor division.

Source code in type_bridge/attribute/numeric.py
def __rfloordiv__(self, other: object) -> Self:
    """Right-hand floor division."""
    if isinstance(other, self._accepted_types):
        return self._create_result(other // self.value)
    return NotImplemented

__mod__

__mod__(other)

Modulo operation.

Source code in type_bridge/attribute/numeric.py
def __mod__(self, other: object) -> Self:
    """Modulo operation."""
    other_val = self._get_operand_value(other)
    if other_val is not None:
        return self._create_result(self.value % other_val)
    return NotImplemented

__rmod__

__rmod__(other)

Right-hand modulo.

Source code in type_bridge/attribute/numeric.py
def __rmod__(self, other: object) -> Self:
    """Right-hand modulo."""
    if isinstance(other, self._accepted_types):
        return self._create_result(other % self.value)
    return NotImplemented

__pow__

__pow__(other)

Power operation.

Source code in type_bridge/attribute/numeric.py
def __pow__(self, other: object) -> Self:
    """Power operation."""
    other_val = self._get_operand_value(other)
    if other_val is not None:
        return self._create_result(self.value**other_val)
    return NotImplemented

__rpow__

__rpow__(other)

Right-hand power.

Source code in type_bridge/attribute/numeric.py
def __rpow__(self, other: object) -> Self:
    """Right-hand power."""
    if isinstance(other, self._accepted_types):
        return self._create_result(other**self.value)
    return NotImplemented

__neg__

__neg__()

Negate the value.

Source code in type_bridge/attribute/numeric.py
def __neg__(self) -> Self:
    """Negate the value."""
    return self._create_result(-self.value)

__pos__

__pos__()

Positive (unary +).

Source code in type_bridge/attribute/numeric.py
def __pos__(self) -> Self:
    """Positive (unary +)."""
    return self._create_result(+self.value)

__abs__

__abs__()

Absolute value.

Source code in type_bridge/attribute/numeric.py
def __abs__(self) -> Self:
    """Absolute value."""
    return self._create_result(abs(self.value))