From 1bfde406e750b95938c5d856a3379436980f996a Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 6 Jul 2023 00:36:58 +0900 Subject: [PATCH 1/3] gh-96844: Improve error message of list.remove --- Doc/library/doctest.rst | 6 +++--- .../2023-07-06-00-35-44.gh-issue-96844.kwvoS-.rst | 1 + Objects/listobject.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-07-06-00-35-44.gh-issue-96844.kwvoS-.rst diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst index d6e4dca0860671..33a1d56e737c30 100644 --- a/Doc/library/doctest.rst +++ b/Doc/library/doctest.rst @@ -409,10 +409,10 @@ Simple example:: >>> [1, 2, 3].remove(42) Traceback (most recent call last): File "", line 1, in - ValueError: list.remove(x): x not in list + ValueError: 42 is not in list -That doctest succeeds if :exc:`ValueError` is raised, with the ``list.remove(x): -x not in list`` detail as shown. +That doctest succeeds if :exc:`ValueError` is raised, with the ``42 is not in list +`` detail as shown. The expected output for an exception must start with a traceback header, which may be either of the following two lines, indented the same as the first line of diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-06-00-35-44.gh-issue-96844.kwvoS-.rst b/Misc/NEWS.d/next/Core and Builtins/2023-07-06-00-35-44.gh-issue-96844.kwvoS-.rst new file mode 100644 index 00000000000000..55334173bc002d --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-07-06-00-35-44.gh-issue-96844.kwvoS-.rst @@ -0,0 +1 @@ +Improve error message of :meth:`list.remove`. Patch by Dong-hee Na. diff --git a/Objects/listobject.c b/Objects/listobject.c index 98fa08962b6aad..144ede6351e03c 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2694,7 +2694,7 @@ list_remove(PyListObject *self, PyObject *value) else if (cmp < 0) return NULL; } - PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list"); + PyErr_Format(PyExc_ValueError, "%R is not in list", value); return NULL; } From 73b699b51b1780f8297587003cdb8b57f50e892f Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 6 Jul 2023 00:41:00 +0900 Subject: [PATCH 2/3] check style --- Doc/library/doctest.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst index 33a1d56e737c30..92da6133f9bf09 100644 --- a/Doc/library/doctest.rst +++ b/Doc/library/doctest.rst @@ -411,8 +411,8 @@ Simple example:: File "", line 1, in ValueError: 42 is not in list -That doctest succeeds if :exc:`ValueError` is raised, with the ``42 is not in list -`` detail as shown. +That doctest succeeds if :exc:`ValueError` is raised, with the ``42 is not in list`` +detail as shown. The expected output for an exception must start with a traceback header, which may be either of the following two lines, indented the same as the first line of From da80bd6f2a602982b6205867a6a5591df79f60ec Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 6 Jul 2023 00:59:43 +0900 Subject: [PATCH 3/3] fix test --- Lib/test/test_xml_etree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 11efee00582e01..b9352cb865d027 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -328,7 +328,7 @@ def test_simpleops(self): self.serialize_check(element, '') # 5 with self.assertRaises(ValueError) as cm: element.remove(subelement) - self.assertEqual(str(cm.exception), 'list.remove(x): x not in list') + self.assertIn('not in list', str(cm.exception)) self.serialize_check(element, '') # 6 element[0:0] = [subelement, subelement, subelement] self.serialize_check(element[1], '') pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy