mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
Get rid of most of the rest of coerce (slot is still there for now).
This commit is contained in:
parent
79212998a8
commit
4886cc331f
19 changed files with 131 additions and 497 deletions
|
|
@ -196,17 +196,6 @@ class BuiltinTest(unittest.TestCase):
|
|||
a.pop(); b.pop(); c.pop()
|
||||
self.assertRaises(TypeError, cmp)
|
||||
|
||||
def test_coerce(self):
|
||||
self.assert_(not fcmp(coerce(1, 1.1), (1.0, 1.1)))
|
||||
self.assertEqual(coerce(1, 1L), (1L, 1L))
|
||||
self.assert_(not fcmp(coerce(1L, 1.1), (1.0, 1.1)))
|
||||
self.assertRaises(TypeError, coerce)
|
||||
class BadNumber:
|
||||
def __coerce__(self, other):
|
||||
raise ValueError
|
||||
self.assertRaises(ValueError, coerce, 42, BadNumber())
|
||||
self.assertRaises(OverflowError, coerce, 0.5, int("12345" * 1000))
|
||||
|
||||
def test_compile(self):
|
||||
compile('print 1\n', '', 'exec')
|
||||
bom = '\xef\xbb\xbf'
|
||||
|
|
|
|||
|
|
@ -92,9 +92,6 @@ class ComplexTest(unittest.TestCase):
|
|||
self.assertAlmostEqual(complex.__floordiv__(3+0j, 1.5+0j), 2)
|
||||
self.assertRaises(ZeroDivisionError, complex.__floordiv__, 3+0j, 0+0j)
|
||||
|
||||
def test_coerce(self):
|
||||
self.assertRaises(OverflowError, complex.__coerce__, 1+1j, 1L<<10000)
|
||||
|
||||
def test_richcompare(self):
|
||||
self.assertRaises(OverflowError, complex.__eq__, 1+1j, 1L<<10000)
|
||||
self.assertEqual(complex.__lt__(1+1j, None), NotImplemented)
|
||||
|
|
|
|||
|
|
@ -2567,33 +2567,6 @@ def rich_comparisons():
|
|||
verify(eval("x %s c[y]" % op) == eval("x %s y" % op),
|
||||
"x=%d, y=%d" % (x, y))
|
||||
|
||||
def coercions():
|
||||
if verbose: print "Testing coercions..."
|
||||
class I(int): pass
|
||||
coerce(I(0), 0)
|
||||
coerce(0, I(0))
|
||||
class L(long): pass
|
||||
coerce(L(0), 0)
|
||||
coerce(L(0), 0L)
|
||||
coerce(0, L(0))
|
||||
coerce(0L, L(0))
|
||||
class F(float): pass
|
||||
coerce(F(0), 0)
|
||||
coerce(F(0), 0L)
|
||||
coerce(F(0), 0.)
|
||||
coerce(0, F(0))
|
||||
coerce(0L, F(0))
|
||||
coerce(0., F(0))
|
||||
class C(complex): pass
|
||||
coerce(C(0), 0)
|
||||
coerce(C(0), 0L)
|
||||
coerce(C(0), 0.)
|
||||
coerce(C(0), 0j)
|
||||
coerce(0, C(0))
|
||||
coerce(0L, C(0))
|
||||
coerce(0., C(0))
|
||||
coerce(0j, C(0))
|
||||
|
||||
def descrdoc():
|
||||
if verbose: print "Testing descriptor doc strings..."
|
||||
def check(descr, what):
|
||||
|
|
@ -3961,11 +3934,8 @@ def notimplemented():
|
|||
('__and__', 'x & y', 'x &= y'),
|
||||
('__or__', 'x | y', 'x |= y'),
|
||||
('__xor__', 'x ^ y', 'x ^= y'),
|
||||
('__coerce__', 'coerce(x, y)', None)]:
|
||||
if name == '__coerce__':
|
||||
rname = name
|
||||
else:
|
||||
rname = '__r' + name[2:]
|
||||
]:
|
||||
rname = '__r' + name[2:]
|
||||
A = metaclass('A', (), {name: specialmethod})
|
||||
B = metaclass('B', (), {rname: specialmethod})
|
||||
a = A()
|
||||
|
|
@ -4043,7 +4013,6 @@ def test_main():
|
|||
str_subclass_as_dict_key()
|
||||
classic_comparisons()
|
||||
rich_comparisons()
|
||||
coercions()
|
||||
descrdoc()
|
||||
setclass()
|
||||
setdict()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue