Patch #1674228: when assigning a slice (old-style), check for the
sq_ass_slice instead of the sq_slice slot.
(backport from rev. 54139)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index b108395..0981f09 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4143,6 +4143,19 @@
check(iexpr, c, N1)
check(iexpr, c, N2)
+def test_assign_slice():
+ # ceval.c's assign_slice used to check for
+ # tp->tp_as_sequence->sq_slice instead of
+ # tp->tp_as_sequence->sq_ass_slice
+
+ class C(object):
+ def __setslice__(self, start, stop, value):
+ self.value = value
+
+ c = C()
+ c[1:2] = 3
+ vereq(c.value, 3)
+
def test_main():
weakref_segfault() # Must be first, somehow
wrapper_segfault()
@@ -4239,6 +4252,7 @@
test_init()
methodwrapper()
notimplemented()
+ test_assign_slice()
if verbose: print "All OK"
diff --git a/Misc/NEWS b/Misc/NEWS
index c3fabfe..7960f07 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@
Core and builtins
-----------------
+- Patch #1674228: when assigning a slice (old-style), check for the
+ sq_ass_slice instead of the sq_slice slot.
+
- Bug #1669182: prevent crash when trying to print an unraisable error
from a string exception.
diff --git a/Python/ceval.c b/Python/ceval.c
index 1ee0f3b..690b2be 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3926,7 +3926,7 @@
PyTypeObject *tp = u->ob_type;
PySequenceMethods *sq = tp->tp_as_sequence;
- if (sq && sq->sq_slice && ISINDEX(v) && ISINDEX(w)) {
+ if (sq && sq->sq_ass_slice && ISINDEX(v) && ISINDEX(w)) {
Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;
if (!_PyEval_SliceIndex(v, &ilow))
return -1;