def _handle_type(self, other): """Helper to handle the return type.""" if isinstance(other, Int): return Float elif isinstance(other, Float): return Float else: raise TypeError( f"Unsuported operation between `{type(self)}` and `{type(other)}`." )
def bind_type(python_value): """Return a Gibica type derived from a Python type.""" binding_table = {'bool': Bool, 'int': Int, 'float': Float} if python_value is None: return NoneType() python_type = type(python_value) gibica_type = binding_table.get(python_type.__name__) if gibica_type is None: raise TypeError('Impossible to recognize underlying type.') return gibica_type(python_value)
def __floordiv__(self, other): """Handle the `//` operator.""" try: return self._handle_type(other)(self.value // other.value) except ZeroDivisionError: raise TypeError('Zero division error.')
def __truediv__(self, other): """Handle the `/` operator.""" try: return Float(self.value / other.value) except ZeroDivisionError: raise TypeError('Zero division error.')
def _type_error(self): """Raise a `TypeError`.""" raise TypeError("Unsupported operation.")
def __setattr__(self, key, value): raise TypeError("Impossible to set a set a NoneType.")