Commits

Mark Dickinson committed a9cd3d0

Apply 2to3 fixes, minus a few unnecessary list() conversions on iterators.

Comments (0)

Files changed (5)

bigfloat_cython/bigfloat/core.py

 
 # Python wrapper for MPFR library
 
-from __future__ import with_statement
 
 import sys as _sys
 import contextlib as _contextlib
             return _set_d(value)
         elif isinstance(value, str):
             return set_str2(value.strip(), 10)
-        elif isinstance(value, unicode):
+        elif isinstance(value, str):
             value = value.strip().encode('ascii')
             return set_str2(value, 10)
-        elif isinstance(value, (int, long)):
+        elif isinstance(value, int):
             return set_str2('%x' % value, 16)
         elif isinstance(value, BigFloat):
             return pos(value)
         """
 
         # figure out precision to use
-        if isinstance(value, basestring):
+        if isinstance(value, str):
             if precision is None:
                 raise TypeError("precision must be supplied when "
                                 "converting from a string")
                                 "from a string")
             if isinstance(value, float):
                 precision = _builtin_max(DBL_PRECISION, PRECISION_MIN)
-            elif isinstance(value, (int, long)):
+            elif isinstance(value, int):
                 precision = _builtin_max(_bit_length(value), PRECISION_MIN)
             elif isinstance(value, BigFloat):
                 precision = value.precision
                 raise ValueError("value too large to represent as a BigFloat")
             if test_flag(Underflow):
                 raise ValueError("value too small to represent as a BigFloat")
-            if test_flag(Inexact) and not isinstance(value, basestring):
+            if test_flag(Inexact) and not isinstance(value, str):
                 # since this is supposed to be an exact conversion, the
                 # inexact flag should never be set except when converting
                 # from a string.
             n >>= -e
         return int(-n) if negative else int(n)
 
-    def __long__(self):
-        return long(int(self))
-
     def __float__(self):
         """BigFloat -> float.
 
 
         sign = '-' if self._sign() else ''
         e = self._exponent()
-        if isinstance(e, basestring):
+        if isinstance(e, str):
             return sign + e
 
         m = self._significand()
     def __ne__(self, other):
         return not (self == other)
 
-    def __nonzero__(self):
+    def __bool__(self):
         return not is_zero(self)
 
     @property
 
         # ints, long and floats mix freely with BigFloats, and are
         # converted exactly.
-        if isinstance(arg, (int, long, float)):
+        if isinstance(arg, (int, float)):
             return cls.exact(arg)
         elif isinstance(arg, BigFloat):
             return arg

bigfloat_cython/bigfloat/test/test___all__.py

 
 class TestAll(unittest.TestCase):
     def test_from_import_star_on_bigfloat_package(self):
-        exec "from bigfloat import *"
+        exec("from bigfloat import *")
 
     def test_duplicates(self):
         # Check for duplicate entries in __all__.

bigfloat_cython/bigfloat/test/test_bigfloat.py

 # along with the bigfloat package.  If not, see <http://www.gnu.org/licenses/>.
 
 # For Python 2.5
-from __future__ import with_statement
+
 
 # Standard library imports
 import doctest
         if (MPFR_VERSION_MAJOR, MPFR_VERSION_MINOR) >= (2, 4):
             fns.append(mod)
 
-        values = [2, 3L, 1.234, BigFloat('0.678'), BigFloat('nan'),
+        values = [2, 3, 1.234, BigFloat('0.678'), BigFloat('nan'),
                   float('0.0'), float('inf'), True]
 
         # functions should accept operands of any integer, float or BigFloat
         # arithmetic operators:  +, -, *, /, **, %
 
         x = BigFloat('17.29')
-        other_values = [2, 3L, 1.234, BigFloat('0.678'), False]
+        other_values = [2, 3, 1.234, BigFloat('0.678'), False]
         test_precisions = [2, 20, 53, 2000]
-        # note that division using '/' should work (giving true division)
-        # whether or not 'from __future__ import division' is enabled.
-        # So we test both operator.div and operator.truediv.
-        operations = [operator.add, operator.mul, operator.div,
+        operations = [operator.add, operator.mul,
                       operator.sub, operator.pow, operator.truediv]
 
         # % operator only works for MPFR version >= 2.4.
             self.assertIs(is_regular(x), False)
 
         zeros = [
-            0, 0L,
+            0,
             float('0.0'), float('-0.0'),
             BigFloat('0.0'), BigFloat('-0.0'),
         ]
             self.assertIs(is_integer(x), True)
             self.assertIs(is_regular(x), False)
 
-        for x in [-31L, -5.13, BigFloat('-2.34e1000')]:
+        for x in [-31, -5.13, BigFloat('-2.34e1000')]:
             self.assertIs(is_nan(x), False)
             self.assertIs(is_inf(x), False)
             self.assertIs(is_zero(x), False)
             self.assertIs(is_negative(x), False)
 
         # test is_integer for finite nonzero values
-        for x in [2, -31L, 24.0, BigFloat('1e100'), sqrt(BigFloat('2e100'))]:
+        for x in [2, -31, 24.0, BigFloat('1e100'), sqrt(BigFloat('2e100'))]:
             self.assertIs(is_integer(x), True)
 
         for x in [2.1, BigFloat(-1.345), sqrt(BigFloat(2))]:
         negatives = [
             float('-inf'), float('-0.0'),
             BigFloat('-inf'), BigFloat('-0.0'),
-            BigFloat(-2.3), -31, -1L,
+            BigFloat(-2.3), -31, -1,
         ]
         for x in negatives:
             self.assertIs(is_negative(x), True)
 
-        for x in [float('inf'), BigFloat('inf'), float('0.0'), 0, 0L, 2L, 123,
+        for x in [float('inf'), BigFloat('inf'), float('0.0'), 0, 2, 123,
                   BigFloat(1.23)]:
             self.assertIs(is_negative(x), False)
 
         # entries have the same value; sublists are ordered by increasing value
         values = [
             [BigFloat('-Infinity'), float('-inf')],
-            [-1L, -1, -1.0, BigFloat(-1.0)],
+            [-1, -1.0, BigFloat(-1.0)],
             [
-                0L, 0,
+                0,
                 float('0.0'), float('-0.0'),
                 BigFloat('0.0'), BigFloat('-0.0'),
             ],
             [BigFloat('4e-324')],
             [4e-324],
             [1e-320, BigFloat(1e-320)],
-            [1L, 1, 1.0, BigFloat(1.0)],
+            [1, 1.0, BigFloat(1.0)],
             [BigFloat(2 ** 53 + 1)],
             [2 ** 53 + 1],
             [BigFloat('Infinity'), float('inf')],
             self.assertIs(unordered(x, y), True)
 
     def test_creation_from_integer(self):
-        test_values = [-23, 0, 100, 7 ** 100, -23L, 0L, 100L]
+        test_values = [-23, 0, 100, 7 ** 100]
         test_precisions = [2, 20, 53, 2000]
         for value in test_values:
             for p in test_precisions:
                        '+nan',
                        'inf',
                        '-inf',
-                       u'-451.001']
+                       '-451.001']
         test_precisions = [2, 20, 53, 2000]
         for value in test_values:
             for p in test_precisions:
         self.assertEqual(flags, set())
 
     def test_exact_creation_from_integer(self):
-        test_values = [-23, 0, 100, 7 ** 100, -23L, 0L, 100L]
+        test_values = [-23, 0, 100, 7 ** 100]
         test_precisions = [2, 20, 53, 2000]
         for value in test_values:
             for p in test_precisions:
                     self.assertEqual(int(bf), value)
 
         self.assertRaises(TypeError, BigFloat.exact, 1, precision=200)
-        self.assertRaises(TypeError, BigFloat.exact, -13L, precision=53)
+        self.assertRaises(TypeError, BigFloat.exact, -13, precision=53)
 
     def test_exact_creation_from_float(self):
         test_values = [-12.3456, float('-0.0'), float('0.0'), 5e-310, -1e308,
                        '+nan',
                        'inf',
                        '-inf',
-                       u'-451.001']
+                       '-451.001']
         test_precisions = [2, 20, 53, 2000]
         for value in test_values:
             for p in test_precisions:
                 sqrt(BigFloat(2), context=RoundTowardNegative),
                 (1592262918131443, 1125899906842624)
             ),
-            (const_pi(), (884279719003555L, 281474976710656L)),
+            (const_pi(), (884279719003555, 281474976710656)),
             (BigFloat('2.0'), (2, 1)),
             (BigFloat('0.5'), (1, 2)),
             (BigFloat('-1.125'), (-9, 8)),

bigfloat_cython/bigfloat/test/test_context.py

 
     def test_attributes(self):
         c = DefaultContext
-        self.assert_(isinstance(c.precision, (int, long)))
-        self.assert_(isinstance(c.emax, (int, long)))
-        self.assert_(isinstance(c.emin, (int, long)))
+        self.assert_(isinstance(c.precision, int))
+        self.assert_(isinstance(c.emax, int))
+        self.assert_(isinstance(c.emin, int))
         self.assert_(isinstance(c.subnormalize, bool))
         self.assert_(c.rounding in all_rounding_modes)
 

bigfloat_cython/bigfloat/test/test_mpfr.py

     def test_constructor(self):
         x = Mpfr(10)
         self.assertIsInstance(x, Mpfr_t)
-        y = Mpfr(20L)
+        y = Mpfr(20)
         self.assertIsInstance(y, Mpfr_t)
 
     def test_get_and_set_prec(self):
 
     def test_fits_slong_p(self):
         x = Mpfr(64)
-        mpfr_set_si(x, sys.maxint, MPFR_RNDN)
+        mpfr_set_si(x, sys.maxsize, MPFR_RNDN)
         self.assertIs(mpfr_fits_slong_p(x, MPFR_RNDN), True)
 
         x = Mpfr(64)
-        mpfr_set_si(x, -sys.maxint - 1, MPFR_RNDN)
+        mpfr_set_si(x, -sys.maxsize - 1, MPFR_RNDN)
         self.assertIs(mpfr_fits_slong_p(x, MPFR_RNDN), True)
 
         x = Mpfr(28)
-        mpfr_set_si(x, sys.maxint, MPFR_RNDN)
+        mpfr_set_si(x, sys.maxsize, MPFR_RNDN)
         self.assertIs(mpfr_fits_slong_p(x, MPFR_RNDN), False)
 
     def test_get_si_and_set_si(self):
         self.assertEqual(mpfr_get_si(x, MPFR_RNDN), 2367)
 
         # Check set_si from long
-        mpfr_set_si(x, 5789L, MPFR_RNDN)
+        mpfr_set_si(x, 5789, MPFR_RNDN)
         self.assertEqual(mpfr_get_si(x, MPFR_RNDN), 5789)
 
         # Check set_si from out-of-range arguments.
         with self.assertRaises(OverflowError):
-            mpfr_set_si(x, sys.maxint + 1, MPFR_RNDN)
+            mpfr_set_si(x, sys.maxsize + 1, MPFR_RNDN)
 
         with self.assertRaises(OverflowError):
-            mpfr_set_si(x, -sys.maxint - 2, MPFR_RNDN)
+            mpfr_set_si(x, -sys.maxsize - 2, MPFR_RNDN)
 
         # None of the above should have set the erange flag.
         self.assertIs(mpfr_erangeflag_p(), False)
 
         # Check get_si with out-of-range values.
         mpfr_set_inf(x, 0)
-        self.assertEqual(mpfr_get_si(x, MPFR_RNDN), sys.maxint)
+        self.assertEqual(mpfr_get_si(x, MPFR_RNDN), sys.maxsize)
         self.assertIs(mpfr_erangeflag_p(), True)
         mpfr_clear_erangeflag()
 
         mpfr_set_inf(x, -1)
-        self.assertEqual(mpfr_get_si(x, MPFR_RNDN), -sys.maxint - 1)
+        self.assertEqual(mpfr_get_si(x, MPFR_RNDN), -sys.maxsize - 1)
         self.assertIs(mpfr_erangeflag_p(), True)
         mpfr_clear_erangeflag()
 
         mpfr_set_d(x, 1e100, MPFR_RNDN)
-        self.assertEqual(mpfr_get_si(x, MPFR_RNDN), sys.maxint)
+        self.assertEqual(mpfr_get_si(x, MPFR_RNDN), sys.maxsize)
         self.assertIs(mpfr_erangeflag_p(), True)
         mpfr_clear_erangeflag()
 
         mpfr_set_d(x, -1e100, MPFR_RNDN)
-        self.assertEqual(mpfr_get_si(x, MPFR_RNDN), -sys.maxint - 1)
+        self.assertEqual(mpfr_get_si(x, MPFR_RNDN), -sys.maxsize - 1)
         self.assertIs(mpfr_erangeflag_p(), True)
         mpfr_clear_erangeflag()
 
 
         # Invalid base
         with self.assertRaises(ValueError):
-            print mpfr_get_str(1, 0, x, MPFR_RNDN)
+            print(mpfr_get_str(1, 0, x, MPFR_RNDN))
         with self.assertRaises(ValueError):
-            print mpfr_get_str(63, 0, x, MPFR_RNDN)
+            print(mpfr_get_str(63, 0, x, MPFR_RNDN))
 
         # Invalid number of digits
         with self.assertRaises(ValueError):
-            print mpfr_get_str(10, 1, x, MPFR_RNDN)
+            print(mpfr_get_str(10, 1, x, MPFR_RNDN))
         with self.assertRaises((ValueError, OverflowError)):
-            print mpfr_get_str(10, -1, x, MPFR_RNDN)
+            print(mpfr_get_str(10, -1, x, MPFR_RNDN))
 
         # Bases other than 10
         x = Mpfr(20)
 
     def test_exponent_bounds(self):
         # Just exercise the exponent bound functions.
-        self.assertIsInstance(mpfr_get_emin(), (int, long))
-        self.assertIsInstance(mpfr_get_emin_min(), (int, long))
-        self.assertIsInstance(mpfr_get_emin_max(), (int, long))
-        self.assertIsInstance(mpfr_get_emax(), (int, long))
-        self.assertIsInstance(mpfr_get_emax_min(), (int, long))
-        self.assertIsInstance(mpfr_get_emax_max(), (int, long))
+        self.assertIsInstance(mpfr_get_emin(), int))
+        self.assertIsInstance(mpfr_get_emin_min(), int)
+        self.assertIsInstance(mpfr_get_emin_max(), int)
+        self.assertIsInstance(mpfr_get_emax(), int)
+        self.assertIsInstance(mpfr_get_emax_min(), int)
+        self.assertIsInstance(mpfr_get_emax_max(), int)
 
     def test_get_and_set_emin(self):
         # Setting exponent bounds