mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
Bug #1772489: make dir() work on traceback objects again.
This commit is contained in:
parent
ee634a4013
commit
3eed765223
2 changed files with 20 additions and 1 deletions
|
@ -283,6 +283,13 @@ class BuiltinTest(unittest.TestCase):
|
||||||
f = Foo()
|
f = Foo()
|
||||||
self.assertRaises(TypeError, dir, f)
|
self.assertRaises(TypeError, dir, f)
|
||||||
|
|
||||||
|
# dir(traceback)
|
||||||
|
try:
|
||||||
|
raise IndexError
|
||||||
|
except:
|
||||||
|
self.assertEqual(len(dir(sys.exc_info()[2])), 4)
|
||||||
|
|
||||||
|
|
||||||
def test_divmod(self):
|
def test_divmod(self):
|
||||||
self.assertEqual(divmod(12, 7), (1, 5))
|
self.assertEqual(divmod(12, 7), (1, 5))
|
||||||
self.assertEqual(divmod(-12, 7), (-2, 2))
|
self.assertEqual(divmod(-12, 7), (-2, 2))
|
||||||
|
|
|
@ -11,6 +11,18 @@
|
||||||
|
|
||||||
#define OFF(x) offsetof(PyTracebackObject, x)
|
#define OFF(x) offsetof(PyTracebackObject, x)
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
tb_dir(PyTracebackObject *self)
|
||||||
|
{
|
||||||
|
return Py_BuildValue("[ssss]", "tb_frame", "tb_next",
|
||||||
|
"tb_lasti", "tb_lineno");
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyMethodDef tb_methods[] = {
|
||||||
|
{"__dir__", (PyCFunction)tb_dir, METH_NOARGS},
|
||||||
|
{NULL, NULL, 0, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
static PyMemberDef tb_memberlist[] = {
|
static PyMemberDef tb_memberlist[] = {
|
||||||
{"tb_next", T_OBJECT, OFF(tb_next), READONLY},
|
{"tb_next", T_OBJECT, OFF(tb_next), READONLY},
|
||||||
{"tb_frame", T_OBJECT, OFF(tb_frame), READONLY},
|
{"tb_frame", T_OBJECT, OFF(tb_frame), READONLY},
|
||||||
|
@ -73,7 +85,7 @@ PyTypeObject PyTraceBack_Type = {
|
||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
0, /* tp_methods */
|
tb_methods, /* tp_methods */
|
||||||
tb_memberlist, /* tp_members */
|
tb_memberlist, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue