'Converts a finite float to a rational number, exactly.
Beware that Fraction.from_float(0.3) != Fraction(3, 10).'

@classmethod
def from_float(cls, f):

    if isinstance(f, numbers.Integral):
        return cls(f)
    elif (not isinstance(f, float)):
        raise TypeError(('%s.from_float()    only    takes    floats,    not    %r    (%s)' % (cls.__name__, f, type(f).__name__)))
    if (math.isnan(f) or math.isinf(f)):
        raise TypeError(('Cannot    convert    %r    to    %s.' % (f, cls.__name__)))
    return cls(*f.as_integer_ratio())
