def _exact_ratio(x):
 try:
  if ((type(x) is float) or (type(x) is Decimal)):
   return x.as_integer_ratio()
  try:
   return (x.numerator, x.denominator)
  except AttributeError:
   try:
    return x.as_integer_ratio()
   except AttributeError:
    pass
 except (OverflowError, ValueError):
  assert (not _isfinite(x))
  return (x, None)
 msg = "can't convert type '{}' to numerator/denominator"
 raise TypeError(msg.format(type(x).__name__))

def _exact_ratio ( x ) : try : if ( ( type ( x ) is float ) or ( type ( x ) is Decimal ) ) : return x . as_integer_ratio ( ) try : return ( x . numerator , x . denominator ) except AttributeError : try : return x . as_integer_ratio ( ) except AttributeError : pass except ( OverflowError , ValueError ) : assert ( not _isfinite ( x ) ) return ( x , None ) msg = "can't convert type '{}' to numerator/denominator" raise TypeError ( msg . format ( type ( x ) . __name__ ) )
return real number x to exact pair .