-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inspect.stack() should return list of named tuples #61012
Comments
Currently inspect.stack() returns a list of 6-tuples. I suggest to make it return a list of named tuples, so code that only needs one tuple element can get it by name. Current behaviour: Suggested behaviour: |
+1 |
Why did you set stage to 'needs patch'? One is already attached. |
Add versionchanged per review. |
This patch looks good to me with the exception that "versionchanged" should be 3.4. |
Fixed that in v3. |
Should a test be added to or changed in test_inspect? Line 163 has a test_stack method that calls inspect.stack. |
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 |
Terry J. Reedy wrote on Sat, Jan 05, 2013 at 01:33:50 +0000:
Makes sense; added a test that tests named attribute access. Thanks for |
New changeset d03730abd2f6 by Antoine Pitrou in branch 'default': |
It seems like this patch had been overlooked. I refreshed it for 3.5, added a couple tests, and pushed it. Thank you, Daniel! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: