@@ -79,9 +79,6 @@ def mpf_convert_arg(cls, x, prec, rounding):
7979        if  isinstance (x , int_types ): return  from_int (x )
8080        if  isinstance (x , float ): return  from_float (x )
8181        if  isinstance (x , cls .context .constant ): return  x .func (prec , rounding )
82-         if  isinstance (x , numbers .Rational ): return  from_rational (x .numerator ,
83-                                                                  x .denominator ,
84-                                                                  prec , rounding )
8582        if  hasattr (x , '_mpf_' ): return  x ._mpf_ 
8683        if  hasattr (x , '_mpmath_' ):
8784            t  =  cls .context .convert (x ._mpmath_ (prec , rounding ))
@@ -92,6 +89,9 @@ def mpf_convert_arg(cls, x, prec, rounding):
9289            if  a  ==  b :
9390                return  a 
9491            raise  ValueError ("can only create mpf from zero-width interval" )
92+         if  isinstance (x , numbers .Rational ): return  from_rational (x .numerator ,
93+                                                                  x .denominator ,
94+                                                                  prec , rounding )
9595        if  type (x ).__module__  ==  'decimal' :
9696            return  from_Decimal (x , prec , rounding )
9797        raise  TypeError ("cannot create mpf from "  +  repr (x ))
@@ -724,6 +724,10 @@ def convert(ctx, x, strings=True):
724724            return  ctx .make_mpc ((from_float (x .real ), from_float (x .imag )))
725725        if  type (x ).__module__  ==  'numpy' : return  ctx .npconvert (x )
726726        prec , rounding  =  ctx ._prec_rounding 
727+         if  hasattr (x , '_mpf_' ): return  ctx .make_mpf (x ._mpf_ )
728+         if  hasattr (x , '_mpc_' ): return  ctx .make_mpc (x ._mpc_ )
729+         if  hasattr (x , '_mpmath_' ):
730+             return  ctx .convert (x ._mpmath_ (prec , rounding ))
727731        if  isinstance (x , numbers .Rational ):
728732            p , q  =  x .numerator , x .denominator 
729733            return  ctx .make_mpf (from_rational (p , q , prec , rounding ))
@@ -733,10 +737,6 @@ def convert(ctx, x, strings=True):
733737                return  ctx .make_mpf (_mpf_ )
734738            except  ValueError :
735739                pass 
736-         if  hasattr (x , '_mpf_' ): return  ctx .make_mpf (x ._mpf_ )
737-         if  hasattr (x , '_mpc_' ): return  ctx .make_mpc (x ._mpc_ )
738-         if  hasattr (x , '_mpmath_' ):
739-             return  ctx .convert (x ._mpmath_ (prec , rounding ))
740740        if  type (x ).__module__  ==  'decimal' :
741741            return  ctx .make_mpf (from_Decimal (x , prec , rounding ))
742742        return  ctx ._convert_fallback (x , strings )
0 commit comments