8000 gh-102755: Add PyErr_DisplayException(exc) (#102756) · warsaw/cpython@9cd991f · GitHub
[go: up one dir, main page]

Skip to content

Commit 9cd991f

Browse files
iritkatrielwarsaw
authored andcommitted
pythongh-102755: Add PyErr_DisplayException(exc) (python#102756)
1 parent eeb34e5 commit 9cd991f

File tree

13 files changed

+76
-78
lines changed

13 files changed

+76
-78
lines changed

Doc/c-api/exceptions.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ Printing and clearing
8686
8787
An exception must be set when calling this function.
8888
89+
.. c:function: void PyErr_DisplayException(PyObject *exc)
90+
91+
Print the standard traceback display of ``exc`` to ``sys.stderr``, including
92+
chained exceptions and notes.
93+
94+
.. versionadded:: 3.12
8995
9096
Raising exceptions
9197
==================

Doc/data/stable_abi.dat

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/whatsnew/3.12.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,10 @@ New Features
947947
the :attr:`~BaseException.args` passed to the exception's constructor.
948948
(Contributed by Mark Shannon in :gh:`101578`.)
949949

950+
* Add :c:func:`PyErr_DisplayException`, which takes an exception instance,
951+
to replace the legacy-api :c:func:`PyErr_Display`. (Contributed by
952+
Irit Katriel in :gh:`102755`).
953+
950954
Porting to Python 3.12
951955
----------------------
952956

@@ -1080,6 +1084,9 @@ Deprecated
10801084
:c:func:`PyErr_SetRaisedException` instead.
10811085
(Contributed by Mark Shannon in :gh:`101578`.)
10821086

1087+
* :c:func:`PyErr_Display` is deprecated. Use :c:func:`PyErr_DisplayException`
1088+
instead. (Contributed by Irit Katriel in :gh:`102755`).
1089+
10831090

10841091
Removed
10851092
-------

Include/internal/pycore_pylifecycle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ PyAPI_FUNC(PyObject*) _PyErr_WriteUnraisableDefaultHook(PyObject *unraisable);
8787
PyAPI_FUNC(void) _PyErr_Print(PyThreadState *tstate);
8888
PyAPI_FUNC(void) _PyErr_Display(PyObject *file, PyObject *exception,
8989
PyObject *value, PyObject *tb);
90+
PyAPI_FUNC(void) _PyErr_DisplayException(PyObject *file, PyObject *exc);
9091

9192
PyAPI_FUNC(void) _PyThreadState_DeleteCurrent(PyThreadState *tstate);
9293

Include/pythonrun.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
1212
PyAPI_FUNC(void) PyErr_Print(void);
1313
PyAPI_FUNC(void) PyErr_PrintEx(int);
1414
PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
15+
PyAPI_FUNC(void) PyErr_DisplayException(PyObject *);
1516

1617

1718
/* Stuff with no proper home (yet) */

Lib/test/test_stable_abi_ctypes.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add :c:func:`PyErr_DisplayException` which takes just an exception instance,
2+
to replace the legacy :c:func:`PyErr_Display` which takes the ``(typ, exc,
3+
tb)`` triplet.

Misc/stable_abi.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@
609609
added = '3.2'
610610
[function.PyErr_Display]
611611
added = '3.2'
612+
[function.PyErr_DisplayException]
613+
added = '3.12'
612614
[function.PyErr_ExceptionMatches]
613615
added = '3.2'
614616
[function.PyErr_Fetch]

Modules/_testcapi/exceptions.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,13 @@ err_restore(PyObject *self, PyObject *args) {
3939
static PyObject *
4040
exception_print(PyObject *self, PyObject *args)
4141
{
42-
PyObject *value;
43-
PyObject *tb = NULL;
42+
PyObject *exc;
4443

45-
if (!PyArg_ParseTuple(args, "O:exception_print", &value)) {
44+
if (!PyArg_ParseTuple(args, "O:exception_print", &exc)) {
4645
return NULL;
4746
}
4847

49-
if (PyExceptionInstance_Check(value)) {
50-
tb = PyException_GetTraceback(value);
51-
}
52-
53-
PyErr_Display((PyObject *) Py_TYPE(value), value, tb);
54-
Py_XDECREF(tb);
55-
48+
PyErr_DisplayException(exc);
5649
Py_RETURN_NONE;
5750
}
5851

PC/python3dll.c

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0