(value, T)
Convert value to given numeric type T.
Convert value to given numeric type T.
Convert value to given numeric type T .
def _convert(value, T):
    """Convert value to given numeric type T."""
    if type(value) is T:
        # This covers the cases where T is Fraction, or where value is
        # a NAN or INF (Decimal or float).
        return value
    if issubclass(T, int) and value.denominator != 1:
        T = float
    try:
        # FIXME: what do we do if this overflows?
        return T(value)
    except TypeError:
        if issubclass(T, Decimal):
            return T(value.numerator) / T(value.denominator)
        else:
            raise
def _convert ( value , T ) : if type ( value ) is T : # This covers the cases where T is Fraction, or where value is # a NAN or INF (Decimal or float). return value if issubclass ( T , int ) and value . denominator != 1 : T = float try : # FIXME: what do we do if this overflows? return T ( value ) except TypeError : if issubclass ( T , Decimal ) : return T ( value . numerator ) / T ( value . denominator ) else : raise