[issue16808] inspect.stack() should return list of named tuples

Meador Inge report at bugs.python.org
Sat Jan 5 03:18:44 CET 2013


Meador Inge added the comment:

I suppose asserting the type wouldn't hurt, but I don't consider it that important:

--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -164,12 +164,16 @@ class TestInterpreterStack(IsTestBase):
         self.assertTrue(len(mod.st) >= 5)
         self.assertEqual(revise(*mod.st[0][1:]),
              (modfile, 16, 'eggs', ['    st = inspect.stack()\n'], 0))
+        self.assertIsInstance(mod.st[0], inspect.FrameInfo)
         self.assertEqual(revise(*mod.st[1][1:]),
              (modfile, 9, 'spam', ['    eggs(b + d, c + f)\n'], 0))
+        self.assertIsInstance(mod.st[1], inspect.FrameInfo)
         self.assertEqual(revise(*mod.st[2][1:]),
              (modfile, 43, 'argue', ['            spam(a, b, c)\n'], 0))
+        self.assertIsInstance(mod.st[2], inspect.FrameInfo)
         self.assertEqual(revise(*mod.st[3][1:]),
              (modfile, 39, 'abuse', ['        self.argue(a, b, c)\n'], 0))
+        self.assertIsInstance(mod.st[3], inspect.FrameInfo)


TestGetClosureVars builds the named tuples directly and compares them.  For example:

        expected = inspect.ClosureVars(nonlocal_vars, global_vars,
                                       builtin_vars, unbound_names)
        self.assertEqual(inspect.getclosurevars(f(_arg)), expected)

Doing this for FrameInfo is awkward because we don't have a frame object to construct
the named tuple with.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16808>
_______________________________________


More information about the Python-bugs-list mailing list