Title: line number for a return in a with block after 3.10 is that of the with, not the return statement · Issue #93975 · python/cpython · GitHub
Open Graph Title: line number for a return in a with block after 3.10 is that of the with, not the return statement · Issue #93975 · python/cpython
X Title: line number for a return in a with block after 3.10 is that of the with, not the return statement · Issue #93975 · python/cpython
Description: def foo() -> int: with open('/dev/null') as devnull: return 'a' In Python 3.10 onwards, the reported line number for the return statement is incorrect. Python main 3.12-main-ish not far from 3.11: >>> def foo() -> int: ... with open('a')...
Open Graph Description: def foo() -> int: with open('/dev/null') as devnull: return 'a' In Python 3.10 onwards, the reported line number for the return statement is incorrect. Python main 3.12-main-ish not far from 3.11: ...
X Description: def foo() -> int: with open('/dev/null') as devnull: return 'a' In Python 3.10 onwards, the reported line number for the return statement is incorrect. Python main 3.12-main-ish ...
Opengraph URL: https://github.com/python/cpython/issues/93975
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"line number for a return in a with block after 3.10 is that of the with, not the return statement","articleBody":"```python\r\ndef foo() -\u003e int:\r\n with open('/dev/null') as devnull:\r\n return 'a'\r\n```\r\n\r\nIn Python 3.10 onwards, the reported line number for the `return` statement is incorrect.\r\n\r\nPython main 3.12-main-ish not far from 3.11:\r\n\r\n```\r\n\u003e\u003e\u003e def foo() -\u003e int:\r\n... with open('a') as f:\r\n... return 'b'\r\n... \r\n\u003e\u003e\u003e dis.dis(foo)\r\n 1 0 RESUME 0\r\n\r\n 2 2 LOAD_GLOBAL 1 (NULL + open)\r\n 14 LOAD_CONST 1 ('a')\r\n 16 CALL 1\r\n 26 BEFORE_WITH\r\n 28 STORE_FAST 0 (f)\r\n\r\n 3 30 NOP\r\n\r\n 2 32 LOAD_CONST 0 (None)\r\n 34 LOAD_CONST 0 (None)\r\n 36 LOAD_CONST 0 (None)\r\n 38 CALL 2\r\n 48 POP_TOP\r\n 50 LOAD_CONST 2 ('b')\r\n 52 RETURN_VALUE\r\n \u003e\u003e 54 PUSH_EXC_INFO\r\n 56 WITH_EXCEPT_START\r\n 58 POP_JUMP_FORWARD_IF_TRUE 4 (to 68)\r\n 60 RERAISE 2\r\n \u003e\u003e 62 COPY 3\r\n 64 POP_EXCEPT\r\n 66 RERAISE 1\r\n \u003e\u003e 68 POP_TOP\r\n 70 POP_EXCEPT\r\n 72 POP_TOP\r\n 74 POP_TOP\r\n 76 LOAD_CONST 0 (None)\r\n 78 RETURN_VALUE\r\nExceptionTable:\r\n 28 to 30 -\u003e 54 [1] lasti\r\n 54 to 60 -\u003e 62 [3] lasti\r\n 68 to 68 -\u003e 62 [3] lasti\r\n\u003e\u003e\u003e sys.version_info\r\nsys.version_info(major=3, minor=12, micro=0, releaselevel='alpha', serial=0)\r\n```\r\n\r\nThe only thing attributed to line 3 is a NOP. The RETURN_VALUE of 'b' is listed as line 2. That is wrong.\r\n\r\nPython 3.9:\r\n\r\n```\r\n\u003e\u003e\u003e def foo() -\u003e int:\r\n... with open('a') as f:\r\n... return 'b'\r\n... \r\n\u003e\u003e\u003e dis.dis(foo)\r\n 2 0 LOAD_GLOBAL 0 (open)\r\n 2 LOAD_CONST 1 ('a')\r\n 4 CALL_FUNCTION 1\r\n 6 SETUP_WITH 18 (to 26)\r\n 8 STORE_FAST 0 (f)\r\n\r\n 3 10 POP_BLOCK\r\n 12 LOAD_CONST 0 (None)\r\n 14 DUP_TOP\r\n 16 DUP_TOP\r\n 18 CALL_FUNCTION 3\r\n 20 POP_TOP\r\n 22 LOAD_CONST 2 ('b')\r\n 24 RETURN_VALUE\r\n \u003e\u003e 26 WITH_EXCEPT_START\r\n 28 POP_JUMP_IF_TRUE 32\r\n 30 RERAISE\r\n \u003e\u003e 32 POP_TOP\r\n 34 POP_TOP\r\n 36 POP_TOP\r\n 38 POP_EXCEPT\r\n 40 POP_TOP\r\n 42 LOAD_CONST 0 (None)\r\n 44 RETURN_VALUE\r\n\u003e\u003e\u003e sys.version_info\r\nsys.version_info(major=3, minor=9, micro=12, releaselevel='final', serial=0)\r\n```\r\n\r\nNoticed by @martindemello working on a 3.10 error attribution bug in pytype.","author":{"url":"https://github.com/gpshead","@type":"Person","name":"gpshead"},"datePublished":"2022-06-18T00:05:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/93975/cpython/issues/93975"}
| 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:4c9911b1-ddd6-e078-1ef5-bace564335b3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D534:169ED8:135D210:19F8A8A:6969AD59 |
| html-safe-nonce | 01a7f8b9e2f943df1c6f19f79bb56d3c2db209078006411efbff0d207563a938 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENTM0OjE2OUVEODoxMzVEMjEwOjE5RjhBOEE6Njk2OUFENTkiLCJ2aXNpdG9yX2lkIjoiMzgwNzg2MTg4ODM1OTQ0MzgwMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ec4ed2c6bbb341b224745f622d2939c6b51abeace93c867b19d0829ed4f0f82d |
| hovercard-subject-tag | issue:1275601441 |
| 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/93975/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9f3d147eeafecde60bfb8a5d9c0e98f74435547f332d076e3ae98d89e910248f/python/cpython/issues/93975 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9f3d147eeafecde60bfb8a5d9c0e98f74435547f332d076e3ae98d89e910248f/python/cpython/issues/93975 |
| og:image:alt | def foo() -> int: with open('/dev/null') as devnull: return 'a' In Python 3.10 onwards, the reported line number for the return statement is incorrect. Python main 3.12-main-ish not far from 3.11: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gpshead |
| hostname | github.com |
| expected-hostname | github.com |
| None | 24c4c97a2d520cb286b35e1a4c22d7a4df3c26a2fa28dd7cdf0e65db327b4de7 |
| 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 | 124667f43168afb6c9c03b7c02eb5b1d2e1be3d9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width