From b9bec7a4476f3e522ff73b92791e077d39abbf37 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 18 Jun 2026 19:12:34 +1000 Subject: [PATCH] Correct length when accessing subscript --- Tests/test_imagepath.py | 1 + src/path.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py index 8d230eb564c..dc9e28d209c 100644 --- a/Tests/test_imagepath.py +++ b/Tests/test_imagepath.py @@ -18,6 +18,7 @@ def test_path() -> None: assert p[0] == (0.0, 1.0) assert p[-1] == (8.0, 9.0) assert list(p[:1]) == [(0.0, 1.0)] + assert list(p[-1:]) == [(8.0, 9.0)] with pytest.raises(TypeError) as cm: p["foo"] assert str(cm.value) == "Path indices must be integers, not str" diff --git a/src/path.c b/src/path.c index b88346d5f8f..89df7550bbe 100644 --- a/src/path.c +++ b/src/path.c @@ -592,7 +592,7 @@ path_subscript(PyPathObject *self, PyObject *item) { return path_getitem(self, i); } if (PySlice_Check(item)) { - int len = 4; + int len = self->count; Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, len, &start, &stop, &step, &slicelength) < 0) {