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 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__
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__
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__
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__
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__
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__
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__
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__
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__
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__
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__
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__
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__
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__
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__
Positive (unary +).
Source code in type_bridge/attribute/numeric.py
| def __pos__(self) -> Self:
"""Positive (unary +)."""
return self._create_result(+self.value)
|
__abs__
Absolute value.
Source code in type_bridge/attribute/numeric.py
| def __abs__(self) -> Self:
"""Absolute value."""
return self._create_result(abs(self.value))
|