Title: `dis.dis()` reports line numbers where there are none. · Issue #107932 · python/cpython · GitHub
Open Graph Title: `dis.dis()` reports line numbers where there are none. · Issue #107932 · python/cpython
X Title: `dis.dis()` reports line numbers where there are none. · Issue #107932 · python/cpython
Description: Take this example function from #107901: def f(): for i in range(30000000): if not i00000: pass dis.dis produces the following output: 1 0 RESUME 0 2 2 LOAD_GLOBAL 1 (range + NULL) 12 LOAD_CONST 1 (30000000) 14 CALL 1 22 GET_ITER >> 2...
Open Graph Description: Take this example function from #107901: def f(): for i in range(30000000): if not i00000: pass dis.dis produces the following output: 1 0 RESUME 0 2 2 LOAD_GLOBAL 1 (range + NULL) 12 LOAD_CONST...
X Description: Take this example function from #107901: def f(): for i in range(30000000): if not i00000: pass dis.dis produces the following output: 1 0 RESUME 0 2 2 LOAD_GLOBAL 1 (range + NULL) 12 LOAD_CONST...
Opengraph URL: https://github.com/python/cpython/issues/107932
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`dis.dis()` reports line numbers where there are none.","articleBody":"Take this example function from https://github.com/python/cpython/issues/107901:\r\n```\r\ndef f():\r\n for i in range(30000000):\r\n if not i%1000000:\r\n pass\r\n```\r\n`dis.dis` produces the following output:\r\n```\r\n 1 0 RESUME 0\r\n\r\n 2 2 LOAD_GLOBAL 1 (range + NULL)\r\n 12 LOAD_CONST 1 (30000000)\r\n 14 CALL 1\r\n 22 GET_ITER\r\n \u003e\u003e 24 FOR_ITER 14 (to 56)\r\n 28 STORE_FAST 0 (i)\r\n\r\n 3 30 LOAD_FAST 0 (i)\r\n 32 LOAD_CONST 2 (1000000)\r\n 34 BINARY_OP 6 (%)\r\n 38 TO_BOOL\r\n 46 POP_JUMP_IF_FALSE 2 (to 52)\r\n 48 JUMP_BACKWARD 14 (to 24)\r\n\r\n 4 \u003e\u003e 52 JUMP_BACKWARD 16 (to 24)\r\n\r\n 2 \u003e\u003e 56 END_FOR\r\n 58 RETURN_CONST 0 (None)\r\n```\r\nWhich has incorrect line numbers.\r\nThe issue is not that the line numbers are wrong, but that you can't tell from the `dis` output.\r\nThe whole point of `dis` is show what is going on at the bytecode level, so it is failing if it gives wrong line numbers.\r\nThe actual line numbers can be see from `co_lines()`\r\n```\r\n\u003e\u003e\u003e list(f.__code__.co_lines())\r\n[(0, 2, 1), (2, 30, 2), (30, 48, 3), (48, 52, None), (52, 56, 4), (56, 60, 2)]\r\n```\r\n\r\nThe correct output should be:\r\n```\r\n 1 0 RESUME 0\r\n\r\n 2 2 LOAD_GLOBAL 1 (range + NULL)\r\n 12 LOAD_CONST 1 (30000000)\r\n 14 CALL 1\r\n 22 GET_ITER\r\n \u003e\u003e 24 FOR_ITER 14 (to 56)\r\n 28 STORE_FAST 0 (i)\r\n\r\n 3 30 LOAD_FAST 0 (i)\r\n 32 LOAD_CONST 2 (1000000)\r\n 34 BINARY_OP 6 (%)\r\n 38 TO_BOOL\r\n 46 POP_JUMP_IF_FALSE 2 (to 52)\r\nNone 48 JUMP_BACKWARD 14 (to 24)\r\n\r\n 4 \u003e\u003e 52 JUMP_BACKWARD 16 (to 24)\r\n\r\n 2 \u003e\u003e 56 END_FOR\r\n 58 RETURN_CONST 0 (None)\r\n```\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-107988\n* gh-108479\n* gh-108478\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/markshannon","@type":"Person","name":"markshannon"},"datePublished":"2023-08-14T09:03:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/107932/cpython/issues/107932"}
| 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:a4ad98d0-5eed-31a8-785c-4ba9ac0f49ef |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 92B6:388B78:19CB30A:218999C:696B3074 |
| html-safe-nonce | cd017c12000692b3d4c2cafe57bf37ab3503fad609f7f1b9ed8cd03eb2d675fa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MkI2OjM4OEI3ODoxOUNCMzBBOjIxODk5OUM6Njk2QjMwNzQiLCJ2aXNpdG9yX2lkIjoiNDAwODg4Mzc1MjQyOTg5MTcwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 636c639848f133566c32200d9989844011b4e316123a82319c9e76a498437e68 |
| hovercard-subject-tag | issue:1849342798 |
| 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/107932/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5e6ad91fc40fa4f3f93a3202660e1c03d9e726e2905af07de22c6dcf82bc7e08/python/cpython/issues/107932 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5e6ad91fc40fa4f3f93a3202660e1c03d9e726e2905af07de22c6dcf82bc7e08/python/cpython/issues/107932 |
| og:image:alt | Take this example function from #107901: def f(): for i in range(30000000): if not i00000: pass dis.dis produces the following output: 1 0 RESUME 0 2 2 LOAD_GLOBAL 1 (range + NULL) 12 LOAD_CONST... |
| 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 | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width