Title: inspect.getsourcelines() is buggy on 3.12 · Issue #104866 · python/cpython · GitHub
Open Graph Title: inspect.getsourcelines() is buggy on 3.12 · Issue #104866 · python/cpython
X Title: inspect.getsourcelines() is buggy on 3.12 · Issue #104866 · python/cpython
Description: % cat gsl.py import inspect def test_list_add(self): def capybara() -> None: assert_is_value( [x] + [y], z, ) assert_is_value( # in the binop implementation a, ) print(inspect.getsourcelines(test_list_add)) % python3.11 gsl.py (['def tes...
Open Graph Description: % cat gsl.py import inspect def test_list_add(self): def capybara() -> None: assert_is_value( [x] + [y], z, ) assert_is_value( # in the binop implementation a, ) print(inspect.getsourcelines(test_l...
X Description: % cat gsl.py import inspect def test_list_add(self): def capybara() -> None: assert_is_value( [x] + [y], z, ) assert_is_value( # in the binop implementation a, ) print(inspect.getsourcelines(tes...
Opengraph URL: https://github.com/python/cpython/issues/104866
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"inspect.getsourcelines() is buggy on 3.12","articleBody":"```\r\n% cat gsl.py\r\nimport inspect\r\n\r\ndef test_list_add(self):\r\n def capybara() -\u003e None:\r\n assert_is_value(\r\n [x] + [y],\r\n z,\r\n )\r\n assert_is_value(\r\n # in the binop implementation\r\n a,\r\n )\r\n\r\nprint(inspect.getsourcelines(test_list_add))\r\n% python3.11 gsl.py \r\n(['def test_list_add(self):\\n', ' def capybara() -\u003e None:\\n', ' assert_is_value(\\n', ' [x] + [y],\\n', ' z,\\n', ' )\\n', ' assert_is_value(\\n', ' # in the binop implementation\\n', ' a,\\n', ' )\\n'], 3)\r\n% ~/py/cpython/python.exe gsl.py \r\n(['def test_list_add(self):\\n', ' def capybara() -\u003e None:\\n', ' assert_is_value(\\n', ' [x] + [y],\\n', ' z,\\n', ' )\\n', ' assert_is_value(\\n', ' # in the binop implementation\\n'], 3)\r\n% ~/py/cpython/python.exe -V\r\nPython 3.12.0b1+\r\n```\r\n\r\nOn 3.12, the last two lines (`a, )`) are not returned as part of the source lines. When I tried to minify by removing the first assert_is_value() call, it instead returned the print() line as part of the function.\r\n\r\nThis looks related to the tokenizer, cc @pablogsal @lysnikolaou.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-104870\n* gh-104872\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2023-05-24T13:47:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/104866/cpython/issues/104866"}
| 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:6da7307c-5e97-62f0-641e-91c9d26e78c2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AB8A:25F5D0:9031E6:C301E5:6969BEBF |
| html-safe-nonce | f8c57e2111ec03a93f415a5dde965fbace7f218c34844184a4ea378f117031ad |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQjhBOjI1RjVEMDo5MDMxRTY6QzMwMUU1OjY5NjlCRUJGIiwidmlzaXRvcl9pZCI6IjYyMDg4NTgwMDM5MzU0NDQ2NzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 18893898ac789d7945cdf57acd3f2a98708e07947d3a47960f6142c484064d4e |
| hovercard-subject-tag | issue:1724046132 |
| 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/104866/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eb351e68003fff283969806a908117df40981872340dccaf2717cb20f9500747/python/cpython/issues/104866 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eb351e68003fff283969806a908117df40981872340dccaf2717cb20f9500747/python/cpython/issues/104866 |
| og:image:alt | % cat gsl.py import inspect def test_list_add(self): def capybara() -> None: assert_is_value( [x] + [y], z, ) assert_is_value( # in the binop implementation a, ) print(inspect.getsourcelines(test_l... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| 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 | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width