Пример #1
0
def test_conversion_failures():
    class A: pass
    class B: pass
    a, b = A(), B()

    with pytest.raises(TypeError):
        convert(a, B)
    with pytest.raises(TypeError):
        convert(b, A)
    with pytest.raises(TypeError):
        get_conversion(A, B)
    with pytest.raises(ValueError):
        get_conversion(a, b)
Пример #2
0
    def convert(self, dtype):
        _float = float

        if dtype is self.dtype:
            return self
        elif dtype is _float:
            x = _float(self._x)
            y = _float(self._y)

            try:
                return self.__float_root(x, y)
            except AttributeError:
                self_t = type(self)
                cls = self_t.__float_root = self.__origin__[2, float]
                return cls(x, y)
        else:
            conv = get_conversion(self.dtype, dtype)
            x = conv(self._x)
            y = conv(self._y)
            return self.__origin__[2, dtype](x, y)
Пример #3
0
    def convert(self, dtype):
        _float = float

        if dtype is self.dtype:
            return self
        elif dtype is _float:
            x = _float(self._x)
            y = _float(self._y)

            try:
                return self.__float_root(x, y)
            except AttributeError:
                self_t = type(self)
                cls = self_t.__float_root = self.__origin__[2, float]
                return cls(x, y)
        else:
            conv = get_conversion(self.dtype, dtype)
            x = conv(self._x)
            y = conv(self._y)
            return self.__origin__[2, dtype](x, y)