summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-09-19 01:25:16 (GMT)
committerGuido van Rossum <guido@python.org>2001-09-19 01:25:16 (GMT)
commit1952e388ca63b8eaa090bef966dd538f78ece208 (patch)
tree31afd318ac859dfbe337d2cf6e11fc6c10bcb45f /Lib/test/test_descr.py
parentd5d8e4a43632d9d4ec9f6fb23f7405c4f0678617 (diff)
downloadcpython-1952e388ca63b8eaa090bef966dd538f78ece208.zip
cpython-1952e388ca63b8eaa090bef966dd538f78ece208.tar.gz
cpython-1952e388ca63b8eaa090bef966dd538f78ece208.tar.bz2
Add additional coercion support for "self subtypes" to int, long,
float (compare the recent checkin to complex). Added tests for these.
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index a57471b..d9c166b 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1924,6 +1924,33 @@ 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 all():
lists()
@@ -1964,6 +1991,7 @@ def all():
str_subclass_as_dict_key()
classic_comparisons()
rich_comparisons()
+ coercions()
all()