Skip to content

Commit

Permalink
Issue python#23641: Cleaned out legacy dunder names from tests and docs.
Browse files Browse the repository at this point in the history
Fixed 2 to 3 porting bug in pynche.ColorDB.
  • Loading branch information
serhiy-storchaka committed Mar 12, 2015
1 parent 18987a1 commit a60c2fe
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Doc/library/multiprocessing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions Doc/library/unittest.mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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__``
Expand Down
7 changes: 4 additions & 3 deletions Lib/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -776,7 +776,8 @@ def day(self):
"""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()."
Expand Down Expand Up @@ -1005,7 +1006,7 @@ class time:
Operators:
__repr__, __str__
__cmp__, __hash__
__eq__, __le__, __lt__, __ge__, __gt__, __hash__
Methods:
Expand Down
11 changes: 5 additions & 6 deletions Lib/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,13 +967,12 @@ def __ge__(self, other, context=None):
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)

Expand Down
15 changes: 3 additions & 12 deletions Lib/sqlite3/test/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,10 @@ def __init__(self, _val):
_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:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/mapping_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_read(self):
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() ...
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ def foo(self, val): pass
# 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):
Expand Down
8 changes: 0 additions & 8 deletions Lib/test/test_augassign.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@ def __imul__(self, val):
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
Expand Down
34 changes: 24 additions & 10 deletions Lib/test/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"rmul",
"truediv",
"rtruediv",
"floordiv",
"rfloordiv",
"mod",
"rmod",
"divmod",
Expand Down Expand Up @@ -174,15 +176,23 @@ def testBinaryOps(self):
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
Expand Down Expand Up @@ -444,12 +454,16 @@ class BadTypeClass:
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):
Expand Down
24 changes: 8 additions & 16 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def __init__(self, *args, **kwargs):
'add': '+',
'sub': '-',
'mul': '*',
'div': '/',
'truediv': '/',
'floordiv': '//',
'divmod': 'divmod',
'pow': '**',
'lshift': '<<',
Expand Down Expand Up @@ -52,8 +53,6 @@ def __init__(self, *args, **kwargs):
'invert': '~',
'int': 'int',
'float': 'float',
'oct': 'oct',
'hex': 'hex',
}

for name, expr in list(self.unops.items()):
Expand Down Expand Up @@ -82,12 +81,6 @@ def unop_test(self, a, res, expr="len(a)", meth="__len__"):
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)
Expand Down Expand Up @@ -221,7 +214,7 @@ def test_dicts(self):
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):
Expand Down Expand Up @@ -261,7 +254,7 @@ def test_complexes(self):
# 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']
Expand Down Expand Up @@ -4160,9 +4153,8 @@ def check(expr, x, y):
('__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'),
Expand Down Expand Up @@ -4224,8 +4216,8 @@ class X(object):
# 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)
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_dynamicclassattribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ def foo(self):
# 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):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def test_classify_metaclass_class_attribute(self):
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')
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def gulp(iterable, keyp=None, func=list):
# 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
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def foo(self):
# 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):
Expand Down
56 changes: 9 additions & 47 deletions Lib/test/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1988,64 +1988,26 @@ def test_ucs4(self):
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:
Expand Down
2 changes: 1 addition & 1 deletion Modules/_decimal/tests/deccheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

# 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'
]

Expand Down
Loading

0 comments on commit a60c2fe

Please sign in to comment.