summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_int.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-25 13:55:54 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-25 13:55:54 (GMT)
commit8d30ad7c8ad5df59be8a65c8f8dab0d13be00dab (patch)
tree65436ba5d34417e9e89804d3b1c2c324edfb2f4e /Lib/test/test_int.py
parent80767a38c74318acbd6fc4bfe228a1d0c0556221 (diff)
downloadcpython-8d30ad7c8ad5df59be8a65c8f8dab0d13be00dab.zip
cpython-8d30ad7c8ad5df59be8a65c8f8dab0d13be00dab.tar.gz
cpython-8d30ad7c8ad5df59be8a65c8f8dab0d13be00dab.tar.bz2
Issue #24731: Fixed crash on converting objects with special methods
__str__, __trunc__, and __float__ returning instances of subclasses of str, long, and float to subclasses of str, long, and float correspondingly.
Diffstat (limited to 'Lib/test/test_int.py')
-rw-r--r--Lib/test/test_int.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py
index 2ca6cf2..0dd8efc 100644
--- a/Lib/test/test_int.py
+++ b/Lib/test/test_int.py
@@ -45,6 +45,9 @@ if have_unicode:
(unichr(0x200), ValueError),
]
+class IntSubclass(int):
+ pass
+
class IntLongCommonTests(object):
"""Mixin of test cases to share between both test_int and test_long."""
@@ -477,6 +480,18 @@ class IntTestCases(IntLongCommonTests, unittest.TestCase):
self.fail("Failed to raise TypeError with %s" %
((base, trunc_result_base),))
+ class TruncReturnsIntSubclass(base):
+ def __trunc__(self):
+ return True
+ good_int = TruncReturnsIntSubclass()
+ n = int(good_int)
+ self.assertEqual(n, 1)
+ self.assertIs(type(n), bool)
+ n = IntSubclass(good_int)
+ self.assertEqual(n, 1)
+ self.assertIs(type(n), IntSubclass)
+
+
def test_main():
run_unittest(IntTestCases)