Skip to content

Commit 4f63193

Browse files
committed
check baseException_repr failure, add 3.15rst
1 parent 28545e5 commit 4f63193

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

Doc/whatsnew/3.15.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ Other language changes
200200
* Several error messages incorrectly using the term "argument" have been corrected.
201201
(Contributed by Stan Ulbrych in :gh:`133382`.)
202202

203+
* The :meth:`repr` of :class:`ImportError` and :class:`ModuleNotFoundError` now
204+
contains attributes name and path.
205+
(Contributed by Serhiy Storchaka, Oleg Iarygin, and Yoav Nir in :gh:`74185`.)
206+
203207

204208
New modules
205209
===========

Lib/test/test_exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,5 +2640,6 @@ def test_ModuleNotFoundError_repr_with_failed_import(self):
26402640
self.assertEqual(repr(cm.exception),
26412641
"ModuleNotFoundError(\"No module named 'does_not_exist'\", name='does_not_exist')")
26422642

2643+
26432644
if __name__ == '__main__':
26442645
unittest.main()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
:meth:`repr` of :class:`ImportError` now contains attributes name and path.
1+
The :meth:`repr` of :class:`ImportError` and :class:`ModuleNotFoundError` now
2+
contains attributes name and path.
23
Patch by Serhiy Storchaka, Oleg Iarygin, and Yoav Nir

Objects/exceptions.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,9 @@ ImportError_repr(PyObject *self)
18741874
goto error;
18751875
}
18761876
PyObject *r = BaseException_repr(self);
1877+
if (r == NULL) {
1878+
goto error;
1879+
}
18771880
if (PyUnicodeWriter_WriteSubstring(
18781881
writer, r, 0, PyUnicode_GET_LENGTH(r) - 1) < 0)
18791882
{
@@ -1903,7 +1906,7 @@ ImportError_repr(PyObject *self)
19031906
}
19041907
}
19051908

1906-
if (PyUnicodeWriter_WriteASCII(writer, ")", 1) < 0) {
1909+
if (PyUnicodeWriter_WriteChar(writer, ")") < 0) {
19071910
goto error;
19081911
}
19091912

0 commit comments

Comments
 (0)