(x)
Return Real number x to exact (numerator, denominator) pair.

    >>> _exact_ratio(0.25)
    (1, 4)

    x is expected to be an int, Fraction, Decimal or float.
Return Real number x to exact (numerator, denominator) pair.
Return Real number x to exact ( numerator denominator ) pair .
def _exact_ratio(x):
    """Return Real number x to exact (numerator, denominator) pair.

    >>> _exact_ratio(0.25)
    (1, 4)

    x is expected to be an int, Fraction, Decimal or float.
    """
    try:
        return x.as_integer_ratio()
    except AttributeError:
        pass
    except (OverflowError, ValueError):
        # float NAN or INF.
        assert not _isfinite(x)
        return (x, None)
    try:
        # x may be an Integral ABC.
        return (x.numerator, x.denominator)
    except AttributeError:
        msg = f"can't convert type '{type(x).__name__}' to numerator/denominator"
        raise TypeError(msg)
def _exact_ratio ( x ) : try : return x . as_integer_ratio ( ) except AttributeError : pass except ( OverflowError , ValueError ) : # float NAN or INF. assert not _isfinite ( x ) return ( x , None ) try : # x may be an Integral ABC. return ( x . numerator , x . denominator ) except AttributeError : msg = f"can't convert type '{type(x).__name__}' to numerator/denominator" raise TypeError ( msg )