Title: Add `show_positions` keyword argument to `dis.dis` and related functions · Issue #123165 · python/cpython · GitHub
Open Graph Title: Add `show_positions` keyword argument to `dis.dis` and related functions · Issue #123165 · python/cpython
X Title: Add `show_positions` keyword argument to `dis.dis` and related functions · Issue #123165 · python/cpython
Description: Feature or enhancement Proposal: dis.dis is a useful debugging tool when trying to debug minor bytecode compiler errors. However it lacks one important feature, the ability to see the exact positions attached to instructions. It can only...
Open Graph Description: Feature or enhancement Proposal: dis.dis is a useful debugging tool when trying to debug minor bytecode compiler errors. However it lacks one important feature, the ability to see the exact positio...
X Description: Feature or enhancement Proposal: dis.dis is a useful debugging tool when trying to debug minor bytecode compiler errors. However it lacks one important feature, the ability to see the exact positio...
Opengraph URL: https://github.com/python/cpython/issues/123165
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add `show_positions` keyword argument to `dis.dis` and related functions","articleBody":"# Feature or enhancement\r\n\r\n### Proposal:\r\n\r\n`dis.dis` is a useful debugging tool when trying to debug minor bytecode compiler errors. \r\nHowever it lacks one important feature, the ability to see the exact positions attached to instructions. It can only show line numbers.\r\n\r\nWe should add a `show_positions` keyword argument to show positions.\r\nFor example, the function:\r\n```Py\r\ndef foo(x):\r\n if x == 2:\r\n return 1\r\n```\r\ndisassembles to:\r\n```\r\n\r\n 2 RESUME 0\r\n\r\n 3 LOAD_FAST 0 (x)\r\n LOAD_CONST 1 (2)\r\n COMPARE_OP 88 (bool(==))\r\n POP_JUMP_IF_FALSE 1 (to L1)\r\n\r\n 4 RETURN_CONST 2 (1)\r\n\r\n 3 L1: RETURN_CONST 0 (None)\r\n```\r\nwith `show_positions` it would disassemble to something like:\r\n```\r\n2:0-2:0 RESUME 0\r\n\r\n3:7-3:8 LOAD_FAST 0 (x)\r\n3:12-3:13 LOAD_CONST 1 (2)\r\n3:7-3:13 COMPARE_OP 88 (bool(==))\r\n3:7-3:13 POP_JUMP_IF_FALSE 1 (to L1)\r\n\r\n4:15-4:16 RETURN_CONST 2 (1)\r\n\r\n3:7-3:13 L1: RETURN_CONST 0 (None)\r\n```\r\n\r\n### Has this already been discussed elsewhere?\r\n\r\nThis is a minor feature, which does not need previous discussion elsewhere\r\n\r\n### Links to previous discussion of this feature:\r\n\r\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-123168\n* gh-123220\n* gh-123808\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/markshannon","@type":"Person","name":"markshannon"},"datePublished":"2024-08-20T08:46:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/123165/cpython/issues/123165"}
| 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:977ba080-0b98-04bc-2c01-79676068eebf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DBBC:31006B:146DEA:1C2B96:696AA084 |
| html-safe-nonce | 9c3c2d590c1799ad0004df00632a0b73d55343de54109d9f5364babacf36272a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQkJDOjMxMDA2QjoxNDZERUE6MUMyQjk2OjY5NkFBMDg0IiwidmlzaXRvcl9pZCI6IjMyMzQ4NDk2NDY5MDI0MTk1ODgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5e8339d007aa8e6ec288b6d0fd564390949d73e127fb7d9252901bac8acb9cd6 |
| hovercard-subject-tag | issue:2475068484 |
| 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/123165/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0520c118f024ed27b6149e38336ceab115550393bd431bf3188f60b1c8201b71/python/cpython/issues/123165 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0520c118f024ed27b6149e38336ceab115550393bd431bf3188f60b1c8201b71/python/cpython/issues/123165 |
| og:image:alt | Feature or enhancement Proposal: dis.dis is a useful debugging tool when trying to debug minor bytecode compiler errors. However it lacks one important feature, the ability to see the exact positio... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | markshannon |
| hostname | github.com |
| expected-hostname | github.com |
| None | a51f97dbb9326f71c08ecb61577457d543c602124d1a2672871258ef37ac5261 |
| 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 | 4bd0eac606c70914085176ef312ebdcd97a8cdf1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width