summaryrefslogtreecommitdiff
path: root/Python/clinic/traceback.c.h
diff options
context:
space:
mode:
authorNathaniel J. Smith <njs@pobox.com>2018-01-07 05:30:18 -0800
committerNick Coghlan <ncoghlan@gmail.com>2018-01-07 23:30:18 +1000
commite46a8af450210ee5c7f0459ad6beddbc626ae60f (patch)
tree7d8abe4ccbec09008bec52d603446599feb84fda /Python/clinic/traceback.c.h
parentd327ae6ba157fb5118df28a86975c5ca523f05e2 (diff)
downloadcpython-git-e46a8af450210ee5c7f0459ad6beddbc626ae60f.tar.gz
bpo-30579: Allow TracebackType creation and tb_next mutation from Python (GH-4793)
Third party projects may wish to hide their own internal machinery in order to present more comprehensible tracebacks to end users (e.g. Jinja2 and Trio both do this). Previously such projects have had to rely on ctypes to do so: https://github.com/pallets/jinja/blob/fe3dadacdf4cf411d0a5b6bbd4d5234697a28af2/jinja2/debug.py#L345 https://github.com/python-trio/trio/blob/1e86b1aee8c0c759f6f239ae53a05d0d3963c629/trio/_core/_multierror.py#L296 This provides a Python level API for creating and modifying real Traceback objects, allowing tracebacks to be edited at runtime. Patch by Nathaniel Smith.
Diffstat (limited to 'Python/clinic/traceback.c.h')
-rw-r--r--Python/clinic/traceback.c.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/Python/clinic/traceback.c.h b/Python/clinic/traceback.c.h
new file mode 100644
index 0000000000..d9daccbbb7
--- /dev/null
+++ b/Python/clinic/traceback.c.h
@@ -0,0 +1,35 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+PyDoc_STRVAR(tb_new__doc__,
+"TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)\n"
+"--\n"
+"\n"
+"Create a new traceback object.");
+
+static PyObject *
+tb_new_impl(PyTypeObject *type, PyObject *tb_next, PyFrameObject *tb_frame,
+ int tb_lasti, int tb_lineno);
+
+static PyObject *
+tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"tb_next", "tb_frame", "tb_lasti", "tb_lineno", NULL};
+ static _PyArg_Parser _parser = {"OO!ii:TracebackType", _keywords, 0};
+ PyObject *tb_next;
+ PyFrameObject *tb_frame;
+ int tb_lasti;
+ int tb_lineno;
+
+ if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
+ &tb_next, &PyFrame_Type, &tb_frame, &tb_lasti, &tb_lineno)) {
+ goto exit;
+ }
+ return_value = tb_new_impl(type, tb_next, tb_frame, tb_lasti, tb_lineno);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=0133130d7d19556f input=a9049054013a1b77]*/