Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit217f47d

Browse files
authored
gh-96844: Improve error message of list.remove (gh-106455)
1 parentc16ea94 commit217f47d

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

‎Doc/library/doctest.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,10 @@ Simple example::
409409
>>> [1, 2, 3].remove(42)
410410
Traceback (most recent call last):
411411
File "<stdin>", line 1, in <module>
412-
ValueError:list.remove(x): x not in list
412+
ValueError:42 is not in list
413413

414-
That doctest succeeds if:exc:`ValueError` is raised, with the ``list.remove(x):
415-
x not in list``detail as shown.
414+
That doctest succeeds if:exc:`ValueError` is raised, with the ``42 is not inlist``
415+
detail as shown.
416416

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

‎Lib/test/test_xml_etree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def test_simpleops(self):
328328
self.serialize_check(element,'<tag key="value" />')# 5
329329
withself.assertRaises(ValueError)ascm:
330330
element.remove(subelement)
331-
self.assertEqual(str(cm.exception),'list.remove(x): xnot in list')
331+
self.assertIn('not in list',str(cm.exception))
332332
self.serialize_check(element,'<tag key="value" />')# 6
333333
element[0:0]= [subelement,subelement,subelement]
334334
self.serialize_check(element[1],'<subtag />')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve error message of:meth:`list.remove`. Patch by Dong-hee Na.

‎Objects/listobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2694,7 +2694,7 @@ list_remove(PyListObject *self, PyObject *value)
26942694
elseif (cmp<0)
26952695
returnNULL;
26962696
}
2697-
PyErr_SetString(PyExc_ValueError,"list.remove(x): x not in list");
2697+
PyErr_Format(PyExc_ValueError,"%R is not in list",value);
26982698
returnNULL;
26992699
}
27002700

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp