Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a60c2fe

Browse files
Issue #23641: Cleaned out legacy dunder names from tests and docs.
Fixed 2 to 3 porting bug in pynche.ColorDB.
1 parent 18987a1 commit a60c2fe

19 files changed

Lines changed: 72 additions & 124 deletions

Doc/library/multiprocessing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ itself. This means, for example, that one shared object can contain a second:
18311831
>>> l = manager.list(range(10))
18321832
>>> l._callmethod('__len__')
18331833
10
1834-
>>> l._callmethod('__getslice__', (2, 7)) # equiv to `l[2:7]`
1834+
>>> l._callmethod('__getitem__', (slice(2, 7),)) # equiv to `l[2:7]`
18351835
[2, 3, 4, 5, 6]
18361836
>>> l._callmethod('__getitem__', (20,)) # equiv to `l[20]`
18371837
Traceback (most recent call last):

Doc/library/unittest.mock.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,19 +1579,19 @@ The full list of supported magic methods is:
15791579
* ``__hash__``, ``__sizeof__``, ``__repr__`` and ``__str__``
15801580
* ``__dir__``, ``__format__`` and ``__subclasses__``
15811581
* ``__floor__``, ``__trunc__`` and ``__ceil__``
1582-
* Comparisons: ``__cmp__``, ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``,
1582+
* Comparisons: ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``,
15831583
``__eq__`` and ``__ne__``
15841584
* Container methods: ``__getitem__``, ``__setitem__``, ``__delitem__``,
1585-
``__contains__``, ``__len__``, ``__iter__``, ``__getslice__``,
1586-
``__setslice__``, ``__reversed__`` and ``__missing__``
1585+
``__contains__``, ``__len__``, ``__iter__``, ``__reversed__``
1586+
and ``__missing__``
15871587
* Context manager: ``__enter__`` and ``__exit__``
15881588
* Unary numeric methods: ``__neg__``, ``__pos__`` and ``__invert__``
15891589
* The numeric methods (including right hand and in-place variants):
1590-
``__add__``, ``__sub__``, ``__mul__``, ``__div__``,
1590+
``__add__``, ``__sub__``, ``__mul__``, ``__div__``,``__truediv__``,
15911591
``__floordiv__``, ``__mod__``, ``__divmod__``, ``__lshift__``,
15921592
``__rshift__``, ``__and__``, ``__xor__``, ``__or__``, and ``__pow__``
1593-
* Numeric conversion methods: ``__complex__``, ``__int__``, ``__float__``,
1594-
``__index__`` and ``__coerce__``
1593+
* Numeric conversion methods: ``__complex__``, ``__int__``, ``__float__``
1594+
and ``__index__``
15951595
* Descriptor methods: ``__get__``, ``__set__`` and ``__delete__``
15961596
* Pickling: ``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``,
15971597
``__getnewargs__``, ``__getstate__`` and ``__setstate__``

Lib/datetime.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ class date:
646646
Operators:
647647
648648
__repr__, __str__
649-
__cmp__, __hash__
649+
__eq__, __le__, __lt__, __ge__, __gt__, __hash__
650650
__add__, __radd__, __sub__ (add/radd only with timedelta arg)
651651
652652
Methods:
@@ -776,7 +776,8 @@ def day(self):
776776
"""day (1-31)"""
777777
return self._day
778778

779-
# Standard conversions, __cmp__, __hash__ (and helpers)
779+
# Standard conversions, __eq__, __le__, __lt__, __ge__, __gt__,
780+
# __hash__ (and helpers)
780781

781782
def timetuple(self):
782783
"Return local time tuple compatible with time.localtime()."
@@ -1005,7 +1006,7 @@ class time:
10051006
Operators:
10061007
10071008
__repr__, __str__
1008-
__cmp__, __hash__
1009+
__eq__, __le__, __lt__, __ge__, __gt__, __hash__
10091010
10101011
Methods:
10111012

Lib/decimal.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,13 +967,12 @@ def __ge__(self, other, context=None):
967967
return self._cmp(other) >= 0
968968

969969
def compare(self, other, context=None):
970-
"""Compares one to another.
970+
"""Compare self to other. Return a decimal value:
971971
972-
-1 => a < b
973-
0 => a = b
974-
1 => a > b
975-
NaN => one is NaN
976-
Like __cmp__, but returns Decimal instances.
972+
a or b is a NaN ==> Decimal('NaN')
973+
a < b ==> Decimal('-1')
974+
a == b ==> Decimal('0')
975+
a > b ==> Decimal('1')
977976
"""
978977
other = _convert_other(other, raiseit=True)
979978

Lib/sqlite3/test/types.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,10 @@ def __init__(self, _val):
8888
_val = _val.decode('utf-8')
8989
self.val = _val
9090

91-
def __cmp__(self, other):
92-
if not isinstance(other, DeclTypesTests.Foo):
93-
raise ValueError
94-
if self.val == other.val:
95-
return 0
96-
else:
97-
return 1
98-
9991
def __eq__(self, other):
100-
c = self.__cmp__(other)
101-
if c is NotImplemented:
102-
return c
103-
return c == 0
92+
if not isinstance(other, DeclTypesTests.Foo):
93+
return NotImplemented
94+
return self.val == other.val
10495

10596
def __conform__(self, protocol):
10697
if protocol is sqlite.PrepareProtocol:

Lib/test/mapping_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_read(self):
6464
self.assertEqual(d, d)
6565
self.assertNotEqual(p, d)
6666
self.assertNotEqual(d, p)
67-
#__non__zero__
67+
#bool
6868
if p: self.fail("Empty mapping must compare to False")
6969
if not d: self.fail("Full mapping must compare to True")
7070
# keys(), items(), iterkeys() ...

Lib/test/test_abc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ def foo(self, val): pass
194194
# check that the property's __isabstractmethod__ descriptor does the
195195
# right thing when presented with a value that fails truth testing:
196196
class NotBool(object):
197-
def __nonzero__(self):
197+
def __bool__(self):
198198
raise ValueError()
199-
__len__ = __nonzero__
199+
__len__ = __bool__
200200
with self.assertRaises(ValueError):
201201
class F(C):
202202
def bar(self):

Lib/test/test_augassign.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,6 @@ def __imul__(self, val):
136136
output.append("__imul__ called")
137137
return self
138138

139-
def __div__(self, val):
140-
output.append("__div__ called")
141-
def __rdiv__(self, val):
142-
output.append("__rdiv__ called")
143-
def __idiv__(self, val):
144-
output.append("__idiv__ called")
145-
return self
146-
147139
def __floordiv__(self, val):
148140
output.append("__floordiv__ called")
149141
return self

Lib/test/test_class.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"rmul",
1616
"truediv",
1717
"rtruediv",
18+
"floordiv",
19+
"rfloordiv",
1820
"mod",
1921
"rmod",
2022
"divmod",
@@ -174,15 +176,23 @@ def testBinaryOps(self):
174176
1 * testme
175177
self.assertCallStack([("__rmul__", (testme, 1))])
176178

177-
if 1/2 == 0:
178-
callLst[:] = []
179-
testme / 1
180-
self.assertCallStack([("__div__", (testme, 1))])
179+
callLst[:] = []
180+
testme / 1
181+
self.assertCallStack([("__truediv__", (testme, 1))])
182+
181183

184+
callLst[:] = []
185+
1 / testme
186+
self.assertCallStack([("__rtruediv__", (testme, 1))])
182187

183-
callLst[:] = []
184-
1 / testme
185-
self.assertCallStack([("__rdiv__", (testme, 1))])
188+
callLst[:] = []
189+
testme // 1
190+
self.assertCallStack([("__floordiv__", (testme, 1))])
191+
192+
193+
callLst[:] = []
194+
1 // testme
195+
self.assertCallStack([("__rfloordiv__", (testme, 1))])
186196

187197
callLst[:] = []
188198
testme % 1
@@ -444,12 +454,16 @@ class BadTypeClass:
444454
def __int__(self):
445455
return None
446456
__float__ = __int__
457+
__complex__ = __int__
447458
__str__ = __int__
448459
__repr__ = __int__
449-
__oct__ = __int__
450-
__hex__ = __int__
460+
__bytes__ = __int__
461+
__bool__ = __int__
462+
__index__ = __int__
463+
def index(x):
464+
return [][x]
451465

452-
for f in [int, float, str, repr, oct, hex]:
466+
for f in [float, complex, str, repr, bytes, bin, oct, hex, bool, index]:
453467
self.assertRaises(TypeError, f, BadTypeClass())
454468

455469
def testHashStuff(self):

Lib/test/test_descr.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def __init__(self, *args, **kwargs):
2121
'add': '+',
2222
'sub': '-',
2323
'mul': '*',
24-
'div': '/',
24+
'truediv': '/',
25+
'floordiv': '//',
2526
'divmod': 'divmod',
2627
'pow': '**',
2728
'lshift': '<<',
@@ -52,8 +53,6 @@ def __init__(self, *args, **kwargs):
5253
'invert': '~',
5354
'int': 'int',
5455
'float': 'float',
55-
'oct': 'oct',
56-
'hex': 'hex',
5756
}
5857

5958
for name, expr in list(self.unops.items()):
@@ -82,12 +81,6 @@ def unop_test(self, a, res, expr="len(a)", meth="__len__"):
8281
def binop_test(self, a, b, res, expr="a+b", meth="__add__"):
8382
d = {'a': a, 'b': b}
8483

85-
# XXX Hack so this passes before 2.3 when -Qnew is specified.
86-
if meth == "__div__" and 1/2 == 0.5:
87-
meth = "__truediv__"
88-
89-
if meth == '__divmod__': pass
90-
9184
self.assertEqual(eval(expr, d), res)
9285
t = type(a)
9386
m = getattr(t, meth)
@@ -221,7 +214,7 @@ def test_dicts(self):
221214
def number_operators(self, a, b, skip=[]):
222215
dict = {'a': a, 'b': b}
223216

224-
for name, expr in list(self.binops.items()):
217+
for name, expr in self.binops.items():
225218
if name not in skip:
226219
name = "__%s__" % name
227220
if hasattr(a, name):
@@ -261,7 +254,7 @@ def test_complexes(self):
261254
# Testing complex operations...
262255
self.number_operators(100.0j, 3.0j, skip=['lt', 'le', 'gt', 'ge',
263256
'int', 'float',
264-
'divmod', 'mod'])
257+
'floordiv', 'divmod', 'mod'])
265258

266259
class Number(complex):
267260
__slots__ = ['prec']
@@ -4160,9 +4153,8 @@ def check(expr, x, y):
41604153
('__add__', 'x + y', 'x += y'),
41614154
('__sub__', 'x - y', 'x -= y'),
41624155
('__mul__', 'x * y', 'x *= y'),
4163-
('__truediv__', 'operator.truediv(x, y)', None),
4164-
('__floordiv__', 'operator.floordiv(x, y)', None),
4165-
('__div__', 'x / y', 'x /= y'),
4156+
('__truediv__', 'x / y', 'x /= y'),
4157+
('__floordiv__', 'x // y', 'x //= y'),
41664158
('__mod__', 'x % y', 'x %= y'),
41674159
('__divmod__', 'divmod(x, y)', None),
41684160
('__pow__', 'x ** y', 'x **= y'),
@@ -4224,8 +4216,8 @@ class X(object):
42244216
# Also check type_getattro for correctness.
42254217
class Meta(type):
42264218
pass
4227-
class X(object):
4228-
__metaclass__ = Meta
4219+
class X(metaclass=Meta):
4220+
pass
42294221
X.a = 42
42304222
Meta.a = Descr("a")
42314223
self.assertEqual(X.a, 42)

0 commit comments

Comments
 (0)