bpo-32468: Better frame repr() (#5067)

bpo-32468: Better frame repr()
This commit is contained in:
Antoine Pitrou 2017-12-31 22:35:22 +01:00 committed by GitHub
parent 0a37a30037
commit 14709144b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 1 deletions

View file

@ -547,6 +547,15 @@ frame_sizeof(PyFrameObject *f)
PyDoc_STRVAR(sizeof__doc__,
"F.__sizeof__() -> size of F in memory, in bytes");
static PyObject *
frame_repr(PyFrameObject *f)
{
int lineno = PyFrame_GetLineNumber(f);
return PyUnicode_FromFormat(
"<frame at %p, file %R, line %d, code %S>",
f, f->f_code->co_filename, lineno, f->f_code->co_name);
}
static PyMethodDef frame_methods[] = {
{"clear", (PyCFunction)frame_clear, METH_NOARGS,
clear__doc__},
@ -565,7 +574,7 @@ PyTypeObject PyFrame_Type = {
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
(reprfunc)frame_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */