Title: code.co_positions behaviour does not match documentation · Issue #100117 · python/cpython · GitHub
Open Graph Title: code.co_positions behaviour does not match documentation · Issue #100117 · python/cpython
X Title: code.co_positions behaviour does not match documentation · Issue #100117 · python/cpython
Description: The documentation of co_positions() says: The iterator returns tuples containing the (start_line, end_line, start_column, end_column). The i-th tuple corresponds to the position of the source code that compiled to the i-th instruction. I...
Open Graph Description: The documentation of co_positions() says: The iterator returns tuples containing the (start_line, end_line, start_column, end_column). The i-th tuple corresponds to the position of the source code ...
X Description: The documentation of co_positions() says: The iterator returns tuples containing the (start_line, end_line, start_column, end_column). The i-th tuple corresponds to the position of the source code ...
Opengraph URL: https://github.com/python/cpython/issues/100117
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"code.co_positions behaviour does not match documentation","articleBody":"The [documentation of co_positions()](https://docs.python.org/3.12/reference/datamodel.html#codeobject.co_positions) says:\r\n\r\n`The iterator returns tuples containing the (start_line, end_line, start_column, end_column). The i-th tuple corresponds to the position of the source code that compiled to the i-th instruction.`\r\n\r\nI think this is incorrect, because the iterator returns tuples for cache entries as well:\r\n\r\n```\r\n\u003e\u003e\u003e def f():\r\n... a.b = 1\r\n... \r\n\u003e\u003e\u003e import dis\r\n\u003e\u003e\u003e dis.dis(f)\r\n 1 0 RESUME 0\r\n\r\n 2 2 LOAD_CONST 1 (1)\r\n 4 LOAD_GLOBAL 0 (a)\r\n 16 STORE_ATTR 1 (b)\r\n 26 LOAD_CONST 0 (None)\r\n 28 RETURN_VALUE\r\n\u003e\u003e\u003e len(list(f.__code__.co_positions()))\r\n15\r\n\u003e\u003e\u003e from pprint import pprint as pp\r\n\u003e\u003e\u003e pp(list(f.__code__.co_positions()))\r\n[(1, 1, 0, 0),\r\n (2, 2, 8, 9),\r\n (2, 2, 2, 3),\r\n (2, 2, 2, 3),\r\n (2, 2, 2, 3),\r\n (2, 2, 2, 3),\r\n (2, 2, 2, 3),\r\n (2, 2, 2, 3),\r\n (2, 2, 2, 5),\r\n (2, 2, 2, 5),\r\n (2, 2, 2, 5),\r\n (2, 2, 2, 5),\r\n (2, 2, 2, 5),\r\n (2, 2, 2, 5),\r\n (2, 2, 2, 5)]\r\n\u003e\u003e\u003e \r\n```\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-100447\n* gh-119364\n* gh-119869\n* gh-119870\n* gh-119871\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/iritkatriel","@type":"Person","name":"iritkatriel"},"datePublished":"2022-12-08T18:22:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/100117/cpython/issues/100117"}
| 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:60b157fa-4a4e-432b-43ba-1d2772f7dad7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB3C:155115:5C76E:7FBC8:69693C7A |
| html-safe-nonce | f61854c7504ddad635a3ad48df02258c8a34974c36bd5c8a7b30ec3472544295 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjNDOjE1NTExNTo1Qzc2RTo3RkJDODo2OTY5M0M3QSIsInZpc2l0b3JfaWQiOiI4MjMwNDc5OTc2MDgzMzA3NjQyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2afe22538db4218e905498abe0bcb71facb081127a5457eaf7fa6cff417e253e |
| hovercard-subject-tag | issue:1485179845 |
| 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/100117/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7f4223e2e93056554cd69ef235b513dda90234dfbca2e5c666e660bd33f4897a/python/cpython/issues/100117 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7f4223e2e93056554cd69ef235b513dda90234dfbca2e5c666e660bd33f4897a/python/cpython/issues/100117 |
| og:image:alt | The documentation of co_positions() says: The iterator returns tuples containing the (start_line, end_line, start_column, end_column). The i-th tuple corresponds to the position of the source code ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iritkatriel |
| hostname | github.com |
| expected-hostname | github.com |
| None | 54182691a21263b584d2e600b758e081b0ff1d10ffc0d2eefa51cf754b43b51d |
| 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 | d69ac0477df0f87da03b8b06cebd187012d7a930 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width