summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2018-09-11 21:46:55 +0300
committerBenjamin Peterson <benjamin@python.org>2018-09-11 12:01:08 -0700
commitb9ced63613a6cc104e0de96f5ee90a47a049e815 (patch)
tree926af6c217fb33b982330979099bc17743a47fcb /Lib/test
parent7a501def4fb98a1d6f15e4a5a006141d6027f948 (diff)
downloadcpython-git-backport-24bd50b-2.7.tar.gz
[2.7] closes bpo-31608: Fix a crash in methods of a subclass of _collections.deque with a bad __new__(). (GH-3788).backport-24bd50b-2.7
(cherry picked from commit 24bd50bdcc97d65130c07d6cd26085fd06c3e972) Co-authored-by: Oren Milman <orenmn@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_deque.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index c81064d9f2..b2819f6584 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -659,6 +659,21 @@ class TestSubclass(unittest.TestCase):
d1 == d2 # not clear if this is supposed to be True or False,
# but it used to give a SystemError
+ @support.cpython_only
+ def test_bug_31608(self):
+ # The interpreter used to crash in specific cases where a deque
+ # subclass returned a non-deque.
+ class X(deque):
+ pass
+ d = X()
+ def bad___new__(cls, *args, **kwargs):
+ return [42]
+ X.__new__ = bad___new__
+ with self.assertRaises(TypeError):
+ d * 42 # shouldn't crash
+ with self.assertRaises(TypeError):
+ d + deque([1, 2, 3]) # shouldn't crash
+
class SubclassWithKwargs(deque):
def __init__(self, newarg=1):