]> granicus.if.org Git - python/commitdiff
Issue #23641: Cleaned out legacy dunder names from tests and docs.
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 12 Mar 2015 19:56:08 +0000 (21:56 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 12 Mar 2015 19:56:08 +0000 (21:56 +0200)
Fixed 2 to 3 porting bug in pynche.ColorDB.

19 files changed:
Doc/library/multiprocessing.rst
Doc/library/unittest.mock.rst
Lib/datetime.py
Lib/decimal.py
Lib/sqlite3/test/types.py
Lib/test/mapping_tests.py
Lib/test/test_abc.py
Lib/test/test_augassign.py
Lib/test/test_class.py
Lib/test/test_descr.py
Lib/test/test_dynamicclassattribute.py
Lib/test/test_inspect.py
Lib/test/test_itertools.py
Lib/test/test_property.py
Lib/test/test_unicode.py
Modules/_decimal/tests/deccheck.py
Modules/mathmodule.c
Tools/clinic/clinic.py
Tools/pynche/ColorDB.py

index ecac5b01a124046bf0512470e7da2ad99ddf4fc4..cbec3305ce51760a6b885270f72d2da0b01ca892 100644 (file)
@@ -1831,7 +1831,7 @@ itself.  This means, for example, that one shared object can contain a second:
          >>> l = manager.list(range(10))
          >>> l._callmethod('__len__')
          10
-         >>> l._callmethod('__getslice__', (2, 7))   # equiv to `l[2:7]`
+         >>> l._callmethod('__getitem__', (slice(2, 7),))  # equiv to `l[2:7]`
          [2, 3, 4, 5, 6]
          >>> l._callmethod('__getitem__', (20,))     # equiv to `l[20]`
          Traceback (most recent call last):
index 845e0c41e63d9a784e3b60cb92426160c47ce7a6..91d5a2782779773127c39286ac5b013ef4c3a82a 100644 (file)
@@ -1579,19 +1579,19 @@ The full list of supported magic methods is:
 * ``__hash__``, ``__sizeof__``, ``__repr__`` and ``__str__``
 * ``__dir__``, ``__format__`` and ``__subclasses__``
 * ``__floor__``, ``__trunc__`` and ``__ceil__``
-* Comparisons: ``__cmp__``, ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``,
+* Comparisons: ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``,
   ``__eq__`` and ``__ne__``
 * Container methods: ``__getitem__``, ``__setitem__``, ``__delitem__``,
-  ``__contains__``, ``__len__``, ``__iter__``, ``__getslice__``,
-  ``__setslice__``, ``__reversed__`` and ``__missing__``
+  ``__contains__``, ``__len__``, ``__iter__``, ``__reversed__``
+  and ``__missing__``
 * Context manager: ``__enter__`` and ``__exit__``
 * Unary numeric methods: ``__neg__``, ``__pos__`` and ``__invert__``
 * The numeric methods (including right hand and in-place variants):
-  ``__add__``, ``__sub__``, ``__mul__``, ``__div__``,
+  ``__add__``, ``__sub__``, ``__mul__``, ``__div__``,``__truediv__``,
   ``__floordiv__``, ``__mod__``, ``__divmod__``, ``__lshift__``,
   ``__rshift__``, ``__and__``, ``__xor__``, ``__or__``, and ``__pow__``
-* Numeric conversion methods: ``__complex__``, ``__int__``, ``__float__``,
-  ``__index__`` and ``__coerce__``
+* Numeric conversion methods: ``__complex__``, ``__int__``, ``__float__``
+  and ``__index__``
 * Descriptor methods: ``__get__``, ``__set__`` and ``__delete__``
 * Pickling: ``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``,
   ``__getnewargs__``, ``__getstate__`` and ``__setstate__``
index 4c442f2139022a0c180ee2e616674252bd4b12a0..34e5d387cfac237489a6bfd600fe778d96e3c91e 100644 (file)
@@ -646,7 +646,7 @@ class date:
     Operators:
 
     __repr__, __str__
-    __cmp__, __hash__
+    __eq__, __le__, __lt__, __ge__, __gt__, __hash__
     __add__, __radd__, __sub__ (add/radd only with timedelta arg)
 
     Methods:
@@ -776,7 +776,8 @@ class date:
         """day (1-31)"""
         return self._day
 
-    # Standard conversions, __cmp__, __hash__ (and helpers)
+    # Standard conversions, __eq__, __le__, __lt__, __ge__, __gt__,
+    # __hash__ (and helpers)
 
     def timetuple(self):
         "Return local time tuple compatible with time.localtime()."
@@ -1005,7 +1006,7 @@ class time:
     Operators:
 
     __repr__, __str__
-    __cmp__, __hash__
+    __eq__, __le__, __lt__, __ge__, __gt__, __hash__
 
     Methods:
 
index b254f9cd86cf74ed72e2735dafc1c5cf1c0e68a1..324e4f91cae84ef3ed2220a20f9daecb307161a2 100644 (file)
@@ -967,13 +967,12 @@ class Decimal(object):
         return self._cmp(other) >= 0
 
     def compare(self, other, context=None):
-        """Compares one to another.
+        """Compare self to other.  Return a decimal value:
 
-        -1 => a < b
-        0  => a = b
-        1  => a > b
-        NaN => one is NaN
-        Like __cmp__, but returns Decimal instances.
+        a or b is a NaN ==> Decimal('NaN')
+        a < b           ==> Decimal('-1')
+        a == b          ==> Decimal('0')
+        a > b           ==> Decimal('1')
         """
         other = _convert_other(other, raiseit=True)
 
index a8fdad9ee13e3531809bf891e490b7f2b280cb05..adad571b9a06b9e25b45629d8299cdd0d48c16a9 100644 (file)
@@ -88,19 +88,10 @@ class DeclTypesTests(unittest.TestCase):
                 _val = _val.decode('utf-8')
             self.val = _val
 
-        def __cmp__(self, other):
-            if not isinstance(other, DeclTypesTests.Foo):
-                raise ValueError
-            if self.val == other.val:
-                return 0
-            else:
-                return 1
-
         def __eq__(self, other):
-            c = self.__cmp__(other)
-            if c is NotImplemented:
-                return c
-            return c == 0
+            if not isinstance(other, DeclTypesTests.Foo):
+                return NotImplemented
+            return self.val == other.val
 
         def __conform__(self, protocol):
             if protocol is sqlite.PrepareProtocol:
index bc12c7756f2d2c77280078be78f2dc8ba9a66112..ff82f4eb7d8988a3f5448ec76c1c0b6e8bba2370 100644 (file)
@@ -64,7 +64,7 @@ class BasicTestMappingProtocol(unittest.TestCase):
         self.assertEqual(d, d)
         self.assertNotEqual(p, d)
         self.assertNotEqual(d, p)
-        #__non__zero__
+        #bool
         if p: self.fail("Empty mapping must compare to False")
         if not d: self.fail("Full mapping must compare to True")
         # keys(), items(), iterkeys() ...
index 93f9dae2151945de17715d559d717fb9ac613cb7..e1765f0d5a54cbaf9407882aebda74a388b421b2 100644 (file)
@@ -194,9 +194,9 @@ class TestABC(unittest.TestCase):
         # check that the property's __isabstractmethod__ descriptor does the
         # right thing when presented with a value that fails truth testing:
         class NotBool(object):
-            def __nonzero__(self):
+            def __bool__(self):
                 raise ValueError()
-            __len__ = __nonzero__
+            __len__ = __bool__
         with self.assertRaises(ValueError):
             class F(C):
                 def bar(self):
index 9a59c58ec066c4dda04abd5a9e14054b867895c0..0e75c6bd3290359363098b3dd328ca8a6e66ff34 100644 (file)
@@ -136,14 +136,6 @@ class AugAssignTest(unittest.TestCase):
                 output.append("__imul__ called")
                 return self
 
-            def __div__(self, val):
-                output.append("__div__ called")
-            def __rdiv__(self, val):
-                output.append("__rdiv__ called")
-            def __idiv__(self, val):
-                output.append("__idiv__ called")
-                return self
-
             def __floordiv__(self, val):
                 output.append("__floordiv__ called")
                 return self
index c7003fbe608b53ef5e5464754691342c14e5dddd..e3883d67b76c2df573de1da8fe7cb7f750645171 100644 (file)
@@ -15,6 +15,8 @@ testmeths = [
     "rmul",
     "truediv",
     "rtruediv",
+    "floordiv",
+    "rfloordiv",
     "mod",
     "rmod",
     "divmod",
@@ -174,15 +176,23 @@ class ClassTests(unittest.TestCase):
         1 * testme
         self.assertCallStack([("__rmul__", (testme, 1))])
 
-        if 1/2 == 0:
-            callLst[:] = []
-            testme / 1
-            self.assertCallStack([("__div__", (testme, 1))])
+        callLst[:] = []
+        testme / 1
+        self.assertCallStack([("__truediv__", (testme, 1))])
+
 
+        callLst[:] = []
+        1 / testme
+        self.assertCallStack([("__rtruediv__", (testme, 1))])
 
-            callLst[:] = []
-            1 / testme
-            self.assertCallStack([("__rdiv__", (testme, 1))])
+        callLst[:] = []
+        testme // 1
+        self.assertCallStack([("__floordiv__", (testme, 1))])
+
+
+        callLst[:] = []
+        1 // testme
+        self.assertCallStack([("__rfloordiv__", (testme, 1))])
 
         callLst[:] = []
         testme % 1
@@ -444,12 +454,16 @@ class ClassTests(unittest.TestCase):
             def __int__(self):
                 return None
             __float__ = __int__
+            __complex__ = __int__
             __str__ = __int__
             __repr__ = __int__
-            __oct__ = __int__
-            __hex__ = __int__
+            __bytes__ = __int__
+            __bool__ = __int__
+            __index__ = __int__
+        def index(x):
+            return [][x]
 
-        for f in [int, float, str, repr, oct, hex]:
+        for f in [float, complex, str, repr, bytes, bin, oct, hex, bool, index]:
             self.assertRaises(TypeError, f, BadTypeClass())
 
     def testHashStuff(self):
index 1de2a992e6b8fc8855f81244b5659a0fa030b014..9a60a12c2983dc178e3af8d1e99938876ae30394 100644 (file)
@@ -21,7 +21,8 @@ class OperatorsTest(unittest.TestCase):
             'add': '+',
             'sub': '-',
             'mul': '*',
-            'div': '/',
+            'truediv': '/',
+            'floordiv': '//',
             'divmod': 'divmod',
             'pow': '**',
             'lshift': '<<',
@@ -52,8 +53,6 @@ class OperatorsTest(unittest.TestCase):
             'invert': '~',
             'int': 'int',
             'float': 'float',
-            'oct': 'oct',
-            'hex': 'hex',
         }
 
         for name, expr in list(self.unops.items()):
@@ -82,12 +81,6 @@ class OperatorsTest(unittest.TestCase):
     def binop_test(self, a, b, res, expr="a+b", meth="__add__"):
         d = {'a': a, 'b': b}
 
-        # XXX Hack so this passes before 2.3 when -Qnew is specified.
-        if meth == "__div__" and 1/2 == 0.5:
-            meth = "__truediv__"
-
-        if meth == '__divmod__': pass
-
         self.assertEqual(eval(expr, d), res)
         t = type(a)
         m = getattr(t, meth)
@@ -221,7 +214,7 @@ class OperatorsTest(unittest.TestCase):
     def number_operators(self, a, b, skip=[]):
         dict = {'a': a, 'b': b}
 
-        for name, expr in list(self.binops.items()):
+        for name, expr in self.binops.items():
             if name not in skip:
                 name = "__%s__" % name
                 if hasattr(a, name):
@@ -261,7 +254,7 @@ class OperatorsTest(unittest.TestCase):
         # Testing complex operations...
         self.number_operators(100.0j, 3.0j, skip=['lt', 'le', 'gt', 'ge',
                                                   'int', 'float',
-                                                  'divmod', 'mod'])
+                                                  'floordiv', 'divmod', 'mod'])
 
         class Number(complex):
             __slots__ = ['prec']
@@ -4160,9 +4153,8 @@ order (MRO) for bases """
                 ('__add__',      'x + y',                   'x += y'),
                 ('__sub__',      'x - y',                   'x -= y'),
                 ('__mul__',      'x * y',                   'x *= y'),
-                ('__truediv__',  'operator.truediv(x, y)',  None),
-                ('__floordiv__', 'operator.floordiv(x, y)', None),
-                ('__div__',      'x / y',                   'x /= y'),
+                ('__truediv__',  'x / y',                   'x /= y'),
+                ('__floordiv__', 'x // y',                  'x //= y'),
                 ('__mod__',      'x % y',                   'x %= y'),
                 ('__divmod__',   'divmod(x, y)',            None),
                 ('__pow__',      'x ** y',                  'x **= y'),
@@ -4224,8 +4216,8 @@ order (MRO) for bases """
         # Also check type_getattro for correctness.
         class Meta(type):
             pass
-        class X(object):
-            __metaclass__ = Meta
+        class X(metaclass=Meta):
+            pass
         X.a = 42
         Meta.a = Descr("a")
         self.assertEqual(X.a, 42)
index 079d6c3224124969d444fd2fa251a95bab8d2ea7..bc6a39bb3762fd6e401b0fba9dcd035316e2dfdb 100644 (file)
@@ -158,9 +158,9 @@ class PropertyTests(unittest.TestCase):
         # check that the DynamicClassAttribute's __isabstractmethod__ descriptor does the
         # right thing when presented with a value that fails truth testing:
         class NotBool(object):
-            def __nonzero__(self):
+            def __bool__(self):
                 raise ValueError()
-            __len__ = __nonzero__
+            __len__ = __bool__
         with self.assertRaises(ValueError):
             class C(object):
                 def foo(self):
index fc3bf07f1c05f174c415887b63045c19fd5f8583..a2bb9b6a2a7a5f85229c3d95875a0a59103037ee 100644 (file)
@@ -786,7 +786,7 @@ class TestClassesAndFunctions(unittest.TestCase):
         class Meta(type):
             fish = 'slap'
             def __dir__(self):
-                return ['__class__', '__modules__', '__name__', 'fish']
+                return ['__class__', '__module__', '__name__', 'fish']
         class Class(metaclass=Meta):
             pass
         should_find = inspect.Attribute('fish', 'data', Meta, 'slap')
index 244598b7529718520af5da2dfcd9a25d192528fe..eb51be4dbc8e7dbd04205a72ce4edf33fbba08fd 100644 (file)
@@ -698,7 +698,7 @@ class TestBasicOps(unittest.TestCase):
         # iter.__next__ failure on inner object
         self.assertRaises(ExpectedError, gulp, delayed_raise(1))
 
-        # __cmp__ failure
+        # __eq__ failure
         class DummyCmp:
             def __eq__(self, dst):
                 raise ExpectedError
index 96eeb88b893a467af8c6c8acf9f8b5b710b9c9f9..cee7203d152799d7e3a5c84c1a54b0b17f20adb9 100644 (file)
@@ -140,9 +140,9 @@ class PropertyTests(unittest.TestCase):
         # check that the property's __isabstractmethod__ descriptor does the
         # right thing when presented with a value that fails truth testing:
         class NotBool(object):
-            def __nonzero__(self):
+            def __bool__(self):
                 raise ValueError()
-            __len__ = __nonzero__
+            __len__ = __bool__
         with self.assertRaises(ValueError):
             class C(object):
                 def foo(self):
index 7735a6bbaa4ac292419dfc65e2a4762fdc6885a1..4f45d39a3c1bdd50264319bb4d773d174ec05f1f 100644 (file)
@@ -1988,64 +1988,26 @@ class UnicodeTest(string_tests.CommonTest,
             self.fail("Should have raised UnicodeDecodeError")
 
     def test_conversion(self):
-        # Make sure __unicode__() works properly
-        class Foo0:
+        # Make sure __str__() works properly
+        class ObjectToStr:
             def __str__(self):
                 return "foo"
 
-        class Foo1:
+        class StrSubclassToStr(str):
             def __str__(self):
                 return "foo"
 
-        class Foo2(object):
-            def __str__(self):
-                return "foo"
-
-        class Foo3(object):
-            def __str__(self):
-                return "foo"
-
-        class Foo4(str):
-            def __str__(self):
-                return "foo"
-
-        class Foo5(str):
-            def __str__(self):
-                return "foo"
-
-        class Foo6(str):
-            def __str__(self):
-                return "foos"
-
-            def __str__(self):
-                return "foou"
-
-        class Foo7(str):
-            def __str__(self):
-                return "foos"
-            def __str__(self):
-                return "foou"
-
-        class Foo8(str):
+        class StrSubclassToStrSubclass(str):
             def __new__(cls, content=""):
                 return str.__new__(cls, 2*content)
             def __str__(self):
                 return self
 
-        class Foo9(str):
-            def __str__(self):
-                return "not unicode"
-
-        self.assertEqual(str(Foo0()), "foo")
-        self.assertEqual(str(Foo1()), "foo")
-        self.assertEqual(str(Foo2()), "foo")
-        self.assertEqual(str(Foo3()), "foo")
-        self.assertEqual(str(Foo4("bar")), "foo")
-        self.assertEqual(str(Foo5("bar")), "foo")
-        self.assertEqual(str(Foo6("bar")), "foou")
-        self.assertEqual(str(Foo7("bar")), "foou")
-        self.assertEqual(str(Foo8("foo")), "foofoo")
-        self.assertEqual(str(Foo9("foo")), "not unicode")
+        self.assertEqual(str(ObjectToStr()), "foo")
+        self.assertEqual(str(StrSubclassToStr("bar")), "foo")
+        s = str(StrSubclassToStrSubclass("foo"))
+        self.assertEqual(s, "foofoo")
+        self.assertIs(type(s), StrSubclassToStrSubclass)
 
     def test_unicode_repr(self):
         class s1:
index c4c5a4461d5b9d6bf2b81c356d07609c28e4ca08..27137b2e49e8d64760d39c843fa78d624e694f8f 100644 (file)
@@ -126,7 +126,7 @@ ContextFunctions = {
 
 # Functions that require a restricted exponent range for reasonable runtimes.
 UnaryRestricted = [
-  '__ceil__', '__floor__', '__int__', '__long__', '__trunc__',
+  '__ceil__', '__floor__', '__int__', '__trunc__',
   'to_integral', 'to_integral_value'
 ]
 
index 910d5ea57debe8a96ca90ffeb58ea16754d2da25..243e2a333bc876fbc830d46f121a7a09015eb87a 100644 (file)
@@ -992,7 +992,7 @@ FUNC1(tanh, tanh, 0,
    Note 4: A similar implementation is in Modules/cmathmodule.c.
    Be sure to update both when making changes.
 
-   Note 5: The signature of math.fsum() differs from __builtin__.sum()
+   Note 5: The signature of math.fsum() differs from builtins.sum()
    because the start argument doesn't make sense in the context of
    accurate summation.  Since the partials table is collapsed before
    returning a result, sum(seq2, start=sum(seq1)) may not equal the
index 65bad5174cc09cd30d9c51915081aa003515f9ab..5dcaa93246fc0d210474a3f8d9b84c205715001d 100755 (executable)
@@ -1830,7 +1830,6 @@ __gt__
 __hash__
 __iadd__
 __iand__
-__idivmod__
 __ifloordiv__
 __ilshift__
 __imod__
index fcf1b87cd27c60cd114707c47fe6d8c2fb8b6499..5ced0e71b543a11b67bc878fcb6462b56ee996db 100644 (file)
@@ -23,7 +23,6 @@ color formats, and for calculating other color values.
 import sys
 import re
 from types import *
-import operator
 
 class BadColor(Exception):
     pass
@@ -230,9 +229,8 @@ def triplet_to_rrggbb(rgbtuple):
     return hexname
 
 
-_maxtuple = (256.0,) * 3
 def triplet_to_fractional_rgb(rgbtuple):
-    return list(map(operator.__div__, rgbtuple, _maxtuple))
+    return [x / 256 for x in rgbtuple]
 
 
 def triplet_to_brightness(rgbtuple):