| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,7 +158,6 @@ typedef struct { | |||
| 158 | 158 | binaryfunc nb_add; | |
| 159 | 159 | binaryfunc nb_subtract; | |
| 160 | 160 | binaryfunc nb_multiply; | |
| 161 | - binaryfunc nb_divide; | ||
| 162 | 161 | binaryfunc nb_remainder; | |
| 163 | 162 | binaryfunc nb_divmod; | |
| 164 | 163 | ternaryfunc nb_power; | |
@@ -182,7 +181,6 @@ typedef struct { | |||
| 182 | 181 | binaryfunc nb_inplace_add; | |
| 183 | 182 | binaryfunc nb_inplace_subtract; | |
| 184 | 183 | binaryfunc nb_inplace_multiply; | |
| 185 | - binaryfunc nb_inplace_divide; | ||
| 186 | 184 | binaryfunc nb_inplace_remainder; | |
| 187 | 185 | ternaryfunc nb_inplace_power; | |
| 188 | 186 | binaryfunc nb_inplace_lshift; | |
@@ -192,7 +190,6 @@ typedef struct { | |||
| 192 | 190 | binaryfunc nb_inplace_or; | |
| 193 | 191 | ||
| 194 | 192 | /* Added in release 2.2 */ | |
| 195 | - /* The following require the Py_TPFLAGS_HAVE_CLASS flag */ | ||
| 196 | 193 | binaryfunc nb_floor_divide; | |
| 197 | 194 | binaryfunc nb_true_divide; | |
| 198 | 195 | binaryfunc nb_inplace_floor_divide; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1135,10 +1135,9 @@ def __mul__(self, other, context=None): | |||
| 1135 | 1135 | return ans | |
| 1136 | 1136 | __rmul__ = __mul__ | |
| 1137 | 1137 | ||
| 1138 | - def __div__(self, other, context=None): | ||
| 1138 | + def __truediv__(self, other, context=None): | ||
| 1139 | 1139 | """Return self / other.""" | |
| 1140 | 1140 | return self._divide(other, context=context) | |
| 1141 | - __truediv__ = __div__ | ||
| 1142 | 1141 | ||
| 1143 | 1142 | def _divide(self, other, divmod = 0, context=None): | |
| 1144 | 1143 | """Return a / b, to context.prec precision. | |
@@ -1306,13 +1305,12 @@ def _divide(self, other, divmod = 0, context=None): | |||
| 1306 | 1305 | ans = ans._fix(context) | |
| 1307 | 1306 | return ans | |
| 1308 | 1307 | ||
| 1309 | - def __rdiv__(self, other, context=None): | ||
| 1310 | - """Swaps self/other and returns __div__.""" | ||
| 1308 | + def __rtruediv__(self, other, context=None): | ||
| 1309 | + """Swaps self/other and returns __truediv__.""" | ||
| 1311 | 1310 | other = _convert_other(other) | |
| 1312 | 1311 | if other is NotImplemented: | |
| 1313 | 1312 | return other | |
| 1314 | - return other.__div__(self, context=context) | ||
| 1315 | - __rtruediv__ = __rdiv__ | ||
| 1313 | + return other.__truediv__(self, context=context) | ||
| 1316 | 1314 | ||
| 1317 | 1315 | def __divmod__(self, other, context=None): | |
| 1318 | 1316 | """ | |
@@ -1384,9 +1382,9 @@ def remainder_near(self, other, context=None): | |||
| 1384 | 1382 | rounding = context._set_rounding_decision(NEVER_ROUND) | |
| 1385 | 1383 | ||
| 1386 | 1384 | if other._sign: | |
| 1387 | - comparison = other.__div__(Decimal(-2), context=context) | ||
| 1385 | + comparison = other.__truediv__(Decimal(-2), context=context) | ||
| 1388 | 1386 | else: | |
| 1389 | - comparison = other.__div__(Decimal(2), context=context) | ||
| 1387 | + comparison = other.__truediv__(Decimal(2), context=context) | ||
| 1390 | 1388 | ||
| 1391 | 1389 | context._set_rounding_decision(rounding) | |
| 1392 | 1390 | context._regard_flags(*flags) | |
@@ -1751,7 +1749,7 @@ def __pow__(self, n, modulo = None, context=None): | |||
| 1751 | 1749 | if n < 0: | |
| 1752 | 1750 | #n is a long now, not Decimal instance | |
| 1753 | 1751 | n = -n | |
| 1754 | - mul = Decimal(1).__div__(mul, context=context) | ||
| 1752 | + mul = Decimal(1).__truediv__(mul, context=context) | ||
| 1755 | 1753 | ||
| 1756 | 1754 | spot = 1 | |
| 1757 | 1755 | while spot <= n: | |
@@ -1972,7 +1970,7 @@ def sqrt(self, context=None): | |||
| 1972 | 1970 | rounding = context._set_rounding(ROUND_HALF_EVEN) | |
| 1973 | 1971 | while 1: | |
| 1974 | 1972 | context.prec = min(2*context.prec - 2, maxp) | |
| 1975 | - ans = half.__mul__(ans.__add__(tmp.__div__(ans, context=context), | ||
| 1973 | + ans = half.__mul__(ans.__add__(tmp.__truediv__(ans, context=context), | ||
| 1976 | 1974 | context=context), context=context) | |
| 1977 | 1975 | if context.prec == maxp: | |
| 1978 | 1976 | break | |
@@ -2454,7 +2452,7 @@ def divide(self, a, b): | |||
| 2454 | 2452 | >>> ExtendedContext.divide(Decimal('2.40E+6'), Decimal('2')) | |
| 2455 | 2453 | Decimal("1.20E+6") | |
| 2456 | 2454 | """ | |
| 2457 | - return a.__div__(b, context=self) | ||
| 2455 | + return a.__truediv__(b, context=self) | ||
| 2458 | 2456 | ||
| 2459 | 2457 | def divide_int(self, a, b): | |
| 2460 | 2458 | """Divides two numbers and returns the integer part of the result. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | x *= 2 | |
| 6 | 6 | x **= 2 | |
| 7 | 7 | x -= 8 | |
| 8 | - x //= 2 | ||
| 8 | + x /= 2 | ||
| 9 | 9 | x //= 1 | |
| 10 | 10 | x %= 12 | |
| 11 | 11 | x &= 2 | |
@@ -19,7 +19,7 @@ | |||
| 19 | 19 | x[0] *= 2 | |
| 20 | 20 | x[0] **= 2 | |
| 21 | 21 | x[0] -= 8 | |
| 22 | - x[0] //= 2 | ||
| 22 | + x[0] /= 2 | ||
| 23 | 23 | x[0] //= 2 | |
| 24 | 24 | x[0] %= 12 | |
| 25 | 25 | x[0] &= 2 | |
@@ -33,7 +33,7 @@ | |||
| 33 | 33 | x[0] *= 2 | |
| 34 | 34 | x[0] **= 2 | |
| 35 | 35 | x[0] -= 8 | |
| 36 | - x[0] //= 2 | ||
| 36 | + x[0] /= 2 | ||
| 37 | 37 | x[0] //= 1 | |
| 38 | 38 | x[0] %= 12 | |
| 39 | 39 | x[0] &= 2 | |
@@ -123,14 +123,6 @@ def __imul__(self, val): | |||
| 123 | 123 | print "__imul__ called" | |
| 124 | 124 | return self | |
| 125 | 125 | ||
| 126 | - def __div__(self, val): | ||
| 127 | - print "__div__ called" | ||
| 128 | - def __rdiv__(self, val): | ||
| 129 | - print "__rdiv__ called" | ||
| 130 | - def __idiv__(self, val): | ||
| 131 | - print "__idiv__ called" | ||
| 132 | - return self | ||
| 133 | - | ||
| 134 | 126 | def __floordiv__(self, val): | |
| 135 | 127 | print "__floordiv__ called" | |
| 136 | 128 | return self | |
@@ -147,6 +139,9 @@ def __truediv__(self, val): | |||
| 147 | 139 | def __itruediv__(self, val): | |
| 148 | 140 | print "__itruediv__ called" | |
| 149 | 141 | return self | |
| 142 | + def __rtruediv__(self, val): | ||
| 143 | + print "__rtruediv__ called" | ||
| 144 | + return self | ||
| 150 | 145 | ||
| 151 | 146 | def __mod__(self, val): | |
| 152 | 147 | print "__mod__ called" | |
@@ -217,16 +212,9 @@ def __ilshift__(self, val): | |||
| 217 | 212 | 1 * x | |
| 218 | 213 | x *= 1 | |
| 219 | 214 | ||
| 220 | - if 1/2 == 0: | ||
| 221 | - x / 1 | ||
| 222 | - 1 / x | ||
| 223 | - x /= 1 | ||
| 224 | - else: | ||
| 225 | - # True division is in effect, so "/" doesn't map to __div__ etc; | ||
| 226 | - # but the canned expected-output file requires that those get called. | ||
| 227 | - x.__div__(1) | ||
| 228 | - x.__rdiv__(1) | ||
| 229 | - x.__idiv__(1) | ||
| 215 | + x / 1 | ||
| 216 | + 1 / x | ||
| 217 | + x /= 1 | ||
| 230 | 218 | ||
| 231 | 219 | x // 1 | |
| 232 | 220 | 1 // x | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -140,8 +140,6 @@ def __truediv__(self, other): | |||
| 140 | 140 | return float(self) / other | |
| 141 | 141 | return NotImplemented | |
| 142 | 142 | ||
| 143 | - __div__ = __truediv__ | ||
| 144 | - | ||
| 145 | 143 | def __rtruediv__(self, other): | |
| 146 | 144 | """Divide two Rats, or a Rat and a number (reversed args).""" | |
| 147 | 145 | if isRat(other): | |
@@ -152,8 +150,6 @@ def __rtruediv__(self, other): | |||
| 152 | 150 | return other / float(self) | |
| 153 | 151 | return NotImplemented | |
| 154 | 152 | ||
| 155 | - __rdiv__ = __rtruediv__ | ||
| 156 | - | ||
| 157 | 153 | def __floordiv__(self, other): | |
| 158 | 154 | """Divide two Rats, returning the floored result.""" | |
| 159 | 155 | if isint(other): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,8 +11,8 @@ | |||
| 11 | 11 | "rsub", | |
| 12 | 12 | "mul", | |
| 13 | 13 | "rmul", | |
| 14 | - "div", | ||
| 15 | - "rdiv", | ||
| 14 | + "truediv", | ||
| 15 | + "rtruediv", | ||
| 16 | 16 | "mod", | |
| 17 | 17 | "rmod", | |
| 18 | 18 | "divmod", | |
@@ -134,16 +134,8 @@ def __%(method)s__(self, *args): | |||
| 134 | 134 | testme * 1 | |
| 135 | 135 | 1 * testme | |
| 136 | 136 | ||
| 137 | - if 1/2 == 0: | ||
| 138 | - testme / 1 | ||
| 139 | - 1 / testme | ||
| 140 | - else: | ||
| 141 | - # True division is in effect, so "/" doesn't map to __div__ etc; but | ||
| 142 | - # the canned expected-output file requires that __div__ etc get called. | ||
| 143 | - testme.__coerce__(1) | ||
| 144 | - testme.__div__(1) | ||
| 145 | - testme.__coerce__(1) | ||
| 146 | - testme.__rdiv__(1) | ||
| 137 | + testme / 1 | ||
| 138 | + 1 / testme | ||
| 147 | 139 | ||
| 148 | 140 | testme % 1 | |
| 149 | 141 | 1 % testme | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,10 +44,10 @@ def __mul__(self,other): | |||
| 44 | 44 | def __rmul__(self,other): | |
| 45 | 45 | return other * self.arg | |
| 46 | 46 | ||
| 47 | - def __div__(self,other): | ||
| 47 | + def __truediv__(self,other): | ||
| 48 | 48 | return self.arg / other | |
| 49 | 49 | ||
| 50 | - def __rdiv__(self,other): | ||
| 50 | + def __rtruediv__(self,other): | ||
| 51 | 51 | return other / self.arg | |
| 52 | 52 | ||
| 53 | 53 | def __pow__(self,other): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,19 +55,15 @@ def check_div(self, x, y): | |||
| 55 | 55 | if x != 0: | |
| 56 | 56 | q = z / x | |
| 57 | 57 | self.assertClose(q, y) | |
| 58 | - q = z.__div__(x) | ||
| 59 | - self.assertClose(q, y) | ||
| 60 | 58 | q = z.__truediv__(x) | |
| 61 | 59 | self.assertClose(q, y) | |
| 62 | 60 | if y != 0: | |
| 63 | 61 | q = z / y | |
| 64 | 62 | self.assertClose(q, x) | |
| 65 | - q = z.__div__(y) | ||
| 66 | - self.assertClose(q, x) | ||
| 67 | 63 | q = z.__truediv__(y) | |
| 68 | 64 | self.assertClose(q, x) | |
| 69 | 65 | ||
| 70 | - def test_div(self): | ||
| 66 | + def test_truediv(self): | ||
| 71 | 67 | simple_real = [float(i) for i in xrange(-5, 6)] | |
| 72 | 68 | simple_complex = [complex(x, y) for x in simple_real for y in simple_real] | |
| 73 | 69 | for x in simple_complex: | |
@@ -84,7 +80,7 @@ def test_div(self): | |||
| 84 | 80 | self.check_div(complex(random(), random()), | |
| 85 | 81 | complex(random(), random())) | |
| 86 | 82 | ||
| 87 | - self.assertRaises(ZeroDivisionError, complex.__div__, 1+1j, 0+0j) | ||
| 83 | + self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j) | ||
| 88 | 84 | # FIXME: The following currently crashes on Alpha | |
| 89 | 85 | # self.assertRaises(OverflowError, pow, 1e200+1j, 1e200+1j) | |
| 90 | 86 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -507,7 +507,7 @@ def __ne__(self, other): | |||
| 507 | 507 | ('+', '__add__', '__radd__'), | |
| 508 | 508 | ('-', '__sub__', '__rsub__'), | |
| 509 | 509 | ('*', '__mul__', '__rmul__'), | |
| 510 | - ('/', '__div__', '__rdiv__'), | ||
| 510 | + ('/', '__truediv__', '__rtruediv__'), | ||
| 511 | 511 | ('%', '__mod__', '__rmod__'), | |
| 512 | 512 | ('//', '__floordiv__', '__rfloordiv__'), | |
| 513 | 513 | ('**', '__pow__', '__rpow__'), | |
@@ -975,7 +975,6 @@ def checkSameDec(operation, useOther=False): | |||
| 975 | 975 | ||
| 976 | 976 | checkSameDec("__abs__") | |
| 977 | 977 | checkSameDec("__add__", True) | |
| 978 | - checkSameDec("__div__", True) | ||
| 979 | 978 | checkSameDec("__divmod__", True) | |
| 980 | 979 | checkSameDec("__cmp__", True) | |
| 981 | 980 | checkSameDec("__float__") | |
@@ -990,7 +989,6 @@ def checkSameDec(operation, useOther=False): | |||
| 990 | 989 | checkSameDec("__pos__") | |
| 991 | 990 | checkSameDec("__pow__", True) | |
| 992 | 991 | checkSameDec("__radd__", True) | |
| 993 | - checkSameDec("__rdiv__", True) | ||
| 994 | 992 | checkSameDec("__rdivmod__", True) | |
| 995 | 993 | checkSameDec("__repr__") | |
| 996 | 994 | checkSameDec("__rfloordiv__", True) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,10 +29,6 @@ def testbinop(a, b, res, expr="a+b", meth="__add__"): | |||
| 29 | 29 | if verbose: print "checking", expr | |
| 30 | 30 | dict = {'a': a, 'b': b} | |
| 31 | 31 | ||
| 32 | - # XXX Hack so this passes before 2.3 when -Qnew is specified. | ||
| 33 | - if meth == "__div__" and 1/2 == 0.5: | ||
| 34 | - meth = "__truediv__" | ||
| 35 | - | ||
| 36 | 32 | vereq(eval(expr, dict), res) | |
| 37 | 33 | t = type(a) | |
| 38 | 34 | m = getattr(t, meth) | |
@@ -4044,9 +4040,8 @@ def check(expr, x, y): | |||
| 4044 | 4040 | ('__add__', 'x + y', 'x += y'), | |
| 4045 | 4041 | ('__sub__', 'x - y', 'x -= y'), | |
| 4046 | 4042 | ('__mul__', 'x * y', 'x *= y'), | |
| 4047 | - ('__truediv__', 'operator.truediv(x, y)', None), | ||
| 4048 | - ('__floordiv__', 'operator.floordiv(x, y)', None), | ||
| 4049 | - ('__div__', 'x / y', 'x /= y'), | ||
| 4043 | + ('__truediv__', 'x / y', None), | ||
| 4044 | + ('__floordiv__', 'x // y', None), | ||
| 4050 | 4045 | ('__mod__', 'x % y', 'x %= y'), | |
| 4051 | 4046 | ('__divmod__', 'divmod(x, y)', None), | |
| 4052 | 4047 | ('__pow__', 'x ** y', 'x **= y'), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -144,11 +144,6 @@ def test_delslice(self): | |||
| 144 | 144 | self.failUnless(operator.delslice(a, 2, 8) is None) | |
| 145 | 145 | self.assert_(a == [0, 1, 8, 9]) | |
| 146 | 146 | ||
| 147 | - def test_div(self): | ||
| 148 | - self.failUnlessRaises(TypeError, operator.div, 5) | ||
| 149 | - self.failUnlessRaises(TypeError, operator.div, None, None) | ||
| 150 | - self.failUnless(operator.floordiv(5, 2) == 2) | ||
| 151 | - | ||
| 152 | 147 | def test_floordiv(self): | |
| 153 | 148 | self.failUnlessRaises(TypeError, operator.floordiv, 5) | |
| 154 | 149 | self.failUnlessRaises(TypeError, operator.floordiv, None, None) | |
@@ -416,7 +411,6 @@ def test_inplace(self): | |||
| 416 | 411 | class C(object): | |
| 417 | 412 | def __iadd__ (self, other): return "iadd" | |
| 418 | 413 | def __iand__ (self, other): return "iand" | |
| 419 | - def __idiv__ (self, other): return "idiv" | ||
| 420 | 414 | def __ifloordiv__(self, other): return "ifloordiv" | |
| 421 | 415 | def __ilshift__ (self, other): return "ilshift" | |
| 422 | 416 | def __imod__ (self, other): return "imod" | |
@@ -431,7 +425,6 @@ def __getitem__(self, other): return 5 # so that C is a sequence | |||
| 431 | 425 | c = C() | |
| 432 | 426 | self.assertEqual(operator.iadd (c, 5), "iadd") | |
| 433 | 427 | self.assertEqual(operator.iand (c, 5), "iand") | |
| 434 | - self.assertEqual(operator.idiv (c, 5), "idiv") | ||
| 435 | 428 | self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv") | |
| 436 | 429 | self.assertEqual(operator.ilshift (c, 5), "ilshift") | |
| 437 | 430 | self.assertEqual(operator.imod (c, 5), "imod") | |
@@ -446,7 +439,6 @@ def __getitem__(self, other): return 5 # so that C is a sequence | |||
| 446 | 439 | self.assertEqual(operator.irepeat (c, 5), "imul") | |
| 447 | 440 | self.assertEqual(operator.__iadd__ (c, 5), "iadd") | |
| 448 | 441 | self.assertEqual(operator.__iand__ (c, 5), "iand") | |
| 449 | - self.assertEqual(operator.__idiv__ (c, 5), "idiv") | ||
| 450 | 442 | self.assertEqual(operator.__ifloordiv__(c, 5), "ifloordiv") | |
| 451 | 443 | self.assertEqual(operator.__ilshift__ (c, 5), "ilshift") | |
| 452 | 444 | self.assertEqual(operator.__imod__ (c, 5), "imod") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments