Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-96844: Improve error message of list.remove #106455

Merged
merged 3 commits into from Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/library/doctest.rst
Expand Up @@ -142,14 +142,14 @@
Simple Usage: Checking Examples in Docstrings
---------------------------------------------

The simplest way to start using doctest (but not necessarily the way you'll

Check warning on line 145 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:mod reference target not found: M
continue to do it) is to end each module :mod:`M` with::

if __name__ == "__main__":
import doctest
doctest.testmod()

:mod:`doctest` then examines docstrings in module :mod:`M`.

Check warning on line 152 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:mod reference target not found: M

Running the module as a script causes the examples in the docstrings to get
executed and verified::
Expand Down Expand Up @@ -381,7 +381,7 @@
What's the Execution Context?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

By default, each time :mod:`doctest` finds a docstring to test, it uses a

Check warning on line 384 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:mod reference target not found: M

Check warning on line 384 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:mod reference target not found: M

Check warning on line 384 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:mod reference target not found: M
*shallow copy* of :mod:`M`'s globals, so that running tests doesn't change the
module's real globals, and so that one test in :mod:`M` can't leave behind
crumbs that accidentally allow another test to work. This means examples can
Expand Down Expand Up @@ -409,10 +409,10 @@
>>> [1, 2, 3].remove(42)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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
Expand Down Expand Up @@ -935,7 +935,7 @@
Optional argument *name* gives the name of the module; by default, or if
``None``, ``m.__name__`` is used.

Optional argument *exclude_empty* defaults to false. If true, objects for which

Check warning on line 938 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:meth reference target not found: doctest.master.summarize
no doctests are found are excluded from consideration. The default is a backward
compatibility hack, so that code still using :meth:`doctest.master.summarize` in
conjunction with :func:`testmod` continues to get output for objects with no
Expand Down Expand Up @@ -972,7 +972,7 @@
Unittest API
------------

As your collection of doctest'ed modules grows, you'll want a way to run all

Check warning on line 975 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:func reference target not found: load_tests
their doctests systematically. :mod:`doctest` provides two functions that can
be used to create :mod:`unittest` test suites from modules and text files
containing doctests. To integrate with :mod:`unittest` test discovery, include
Expand All @@ -995,7 +995,7 @@
Convert doctest tests from one or more text files to a
:class:`unittest.TestSuite`.

The returned :class:`unittest.TestSuite` is to be run by the unittest framework

Check warning on line 998 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:exc reference target not found: failureException
and runs the interactive examples in each file. If an example in any file
fails, then the synthesized unit test fails, and a :exc:`failureException`
exception is raised showing the name of the file containing the test and a
Expand Down Expand Up @@ -1061,7 +1061,7 @@

Convert doctest tests for a module to a :class:`unittest.TestSuite`.

The returned :class:`unittest.TestSuite` is to be run by the unittest framework

Check warning on line 1064 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:exc reference target not found: failureException
and runs each doctest in the module. If any of the doctests fail, then the
synthesized unit test fails, and a :exc:`failureException` exception is raised
showing the name of the file containing the test and a (sometimes approximate)
Expand Down Expand Up @@ -1091,7 +1091,7 @@
contains no docstrings instead of raising :exc:`ValueError`.


Under the covers, :func:`DocTestSuite` creates a :class:`unittest.TestSuite` out

Check warning on line 1094 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:class reference target not found: doctest.DocTestCase
of :class:`doctest.DocTestCase` instances, and :class:`DocTestCase` is a
subclass of :class:`unittest.TestCase`. :class:`DocTestCase` isn't documented
here (it's an internal detail), but studying its code can answer questions about
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_xml_etree.py
Expand Up @@ -328,7 +328,7 @@ def test_simpleops(self):
self.serialize_check(element, '<tag key="value" />') # 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, '<tag key="value" />') # 6
element[0:0] = [subelement, subelement, subelement]
self.serialize_check(element[1], '<subtag />')
Expand Down
@@ -0,0 +1 @@
Improve error message of :meth:`list.remove`. Patch by Dong-hee Na.
2 changes: 1 addition & 1 deletion Objects/listobject.c
Expand Up @@ -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;
}

Expand Down