Title: pdb loses local variable change after command longlist · Issue #101673 · python/cpython · GitHub
Open Graph Title: pdb loses local variable change after command longlist · Issue #101673 · python/cpython
X Title: pdb loses local variable change after command longlist · Issue #101673 · python/cpython
Description: Bug report In pdb, ll will clear the local variable change. def main(): a = 1 breakpoint() print(a) main() -> print(a) (Pdb) p a 1 (Pdb) !a = 2 (Pdb) p a 2 (Pdb) ll 1 def main(): 2 a = 1 3 breakpoint() 4 -> print(a) (Pdb) p a 1 (Pdb) s 1...
Open Graph Description: Bug report In pdb, ll will clear the local variable change. def main(): a = 1 breakpoint() print(a) main() -> print(a) (Pdb) p a 1 (Pdb) !a = 2 (Pdb) p a 2 (Pdb) ll 1 def main(): 2 a = 1 3 breakpoi...
X Description: Bug report In pdb, ll will clear the local variable change. def main(): a = 1 breakpoint() print(a) main() -> print(a) (Pdb) p a 1 (Pdb) !a = 2 (Pdb) p a 2 (Pdb) ll 1 def main(): 2 a = 1 3 break...
Opengraph URL: https://github.com/python/cpython/issues/101673
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"pdb loses local variable change after command longlist","articleBody":"# Bug report\r\n\r\nIn pdb, `ll` will clear the local variable change.\r\n\r\n```python\r\ndef main():\r\n a = 1\r\n breakpoint()\r\n print(a)\r\n\r\nmain()\r\n```\r\n\r\n```python\r\n-\u003e print(a)\r\n(Pdb) p a\r\n1\r\n(Pdb) !a = 2\r\n(Pdb) p a\r\n2\r\n(Pdb) ll\r\n 1 def main():\r\n 2 a = 1\r\n 3 breakpoint()\r\n 4 -\u003e print(a)\r\n(Pdb) p a\r\n1\r\n(Pdb) s\r\n1\r\n--Return--\r\n```\r\n\r\nAs you can tell, `a` was changed through `!a = 2` but it was reverted after `ll`. `print(a)` also prints the unmodified value. Without `ll`, everything works fine.\r\n\r\nThe reason lies in `getsourcelines` in `pdb.py`. In that function, it tried to access `obj.f_locals`, which will refresh the dict with `PyFrame_FastToLocalsWithError` as it's a property now.\r\n\r\n```python\r\nif inspect.isframe(obj) and obj.f_globals is obj.f_locals:\r\n```\r\n\r\nAs a result, the local variable changes will be erased.\r\n\r\nThe original reason to check if `obj.f_globals is obj.f_locals` is to check whether `obj` is an module frame. Now that it has side effects to pdb, we can do the check with:\r\n\r\n```python\r\nif inspect.isframe(obj) and obj.f_code.co_name == \"\u003cmodule\u003e\":\r\n```\r\n\r\nIt might not be the most delicate way, but I can't think of a situation where this won't work.\r\n\r\nI did this change locally and I have confirmed:\r\n\r\n1. `./python -m test -j3` passed\r\n2. The original bug is fixed\r\n3. `ll` still prints the full file for module frame\r\n\r\nI'll make a PR soon and please let me know if there are any concerns about the fix.\r\n\r\n# Your environment\r\n\r\n- CPython versions tested on: 3.11.1\r\n- Operating system and architecture: Ubuntu 20.04\r\n\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-101674\n* gh-102632\n* gh-102633\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/gaogaotiantian","@type":"Person","name":"gaogaotiantian"},"datePublished":"2023-02-08T03:59:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/101673/cpython/issues/101673"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:19dcfde1-b763-eace-9b4d-65bd44b246eb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D32C:15468B:E30269:1409EFB:696A6891 |
| html-safe-nonce | f1d56b9a97c478f6e031057679d54c1dc6ffda41646d13bf9978842f7f0cada3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzJDOjE1NDY4QjpFMzAyNjk6MTQwOUVGQjo2OTZBNjg5MSIsInZpc2l0b3JfaWQiOiI3NTE3MjY5NDIzNTgwNDA3OTU0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3b4a31bcc5fdb77d04567cc296cbe787d7777366811003f4c38c9ef0536aa421 |
| hovercard-subject-tag | issue:1575423001 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/101673/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3743dd949ec2f2a3e4b50bb93186d0fef53cb02c0e2e39d093ce1d21c9da14bd/python/cpython/issues/101673 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3743dd949ec2f2a3e4b50bb93186d0fef53cb02c0e2e39d093ce1d21c9da14bd/python/cpython/issues/101673 |
| og:image:alt | Bug report In pdb, ll will clear the local variable change. def main(): a = 1 breakpoint() print(a) main() -> print(a) (Pdb) p a 1 (Pdb) !a = 2 (Pdb) p a 2 (Pdb) ll 1 def main(): 2 a = 1 3 breakpoi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gaogaotiantian |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6fea32d5b7276b841b7a803796d9715bc6cfb31ed549fdf9de2948ac25d12ba6 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f2d9f6432a5a115ec709295ae70623f33bb80aee |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width