Skip to content

Commit 2708582

Browse files
Commit
1 parent 1f2026b commit 2708582

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

Doc/library/doctest.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ Simple example::
471471
>>> [1, 2, 3].remove(42)
472472
Traceback (most recent call last):
473473
File "<stdin>", line 1, in <module>
474-
ValueError: list.remove(x): x not in list
474+
ValueError: 42 not in list
475475

476-
That doctest succeeds if :exc:`ValueError` is raised, with the ``list.remove(x):
477-
x not in list`` detail as shown.
476+
That doctest succeeds if :exc:`ValueError` is raised, with the
477+
``42 not in list`` detail as shown.
478478

479479
The expected output for an exception must start with a traceback header, which
480480
may be either of the following two lines, indented the same as the first line of

Lib/multiprocessing/shared_memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,6 @@ def index(self, value):
539539
if value == entry:
540540
return position
541541
else:
542-
raise ValueError("ShareableList.index(x): x not in list")
542+
raise ValueError(f"{value} not in list")
543543

544544
__class_getitem__ = classmethod(types.GenericAlias)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:func:`list.remove` and :func:`list.index` now raise with more informative
2+
error messages.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:meth:`multiprocessing.shared_memory.ShareableList` now rasies with a more
2+
informative error message.

Objects/listobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,7 @@ list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start,
33053305
else if (cmp < 0)
33063306
return NULL;
33073307
}
3308-
PyErr_SetString(PyExc_ValueError, "list.index(x): x not in list");
3308+
PyErr_Format(PyExc_ValueError, "%R not in list", value);
33093309
return NULL;
33103310
}
33113311

@@ -3375,7 +3375,7 @@ list_remove_impl(PyListObject *self, PyObject *value)
33753375
else if (cmp < 0)
33763376
return NULL;
33773377
}
3378-
PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list");
3378+
PyErr_Format(PyExc_ValueError, "%R not in list", value);
33793379
return NULL;
33803380
}
33813381

0 commit comments

Comments
 (0)