Title: Add modern alternatives to `inspect` module, deprecate old incorrect APIs · Issue #108901 · python/cpython · GitHub
Open Graph Title: Add modern alternatives to `inspect` module, deprecate old incorrect APIs · Issue #108901 · python/cpython
X Title: Add modern alternatives to `inspect` module, deprecate old incorrect APIs · Issue #108901 · python/cpython
Description: Feature or enhancement Proposal: I propose to provide modern alternatives to and deprecate these inspect members: getargs() undocumented helper used in getargvalues. It works with __code__ objects. Can it be replaced with modern tooling?...
Open Graph Description: Feature or enhancement Proposal: I propose to provide modern alternatives to and deprecate these inspect members: getargs() undocumented helper used in getargvalues. It works with __code__ objects....
X Description: Feature or enhancement Proposal: I propose to provide modern alternatives to and deprecate these inspect members: getargs() undocumented helper used in getargvalues. It works with __code__ objects....
Opengraph URL: https://github.com/python/cpython/issues/108901
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add modern alternatives to `inspect` module, deprecate old incorrect APIs","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nI propose to provide modern alternatives to and deprecate these `inspect` members:\n\n- `getargs()` undocumented helper used in getargvalues. It works with `__code__` objects. Can it be replaced with modern tooling? Not yet: we have an internal helper to get signatures from `__code__` objects: [https://github.com/python/cpython/blob/39ef93edb9802dccdb6555d4209ac2e60875a011/Lib/inspect.py#L2423-L2488 ](https://github.com/python/cpython/blob/39ef93edb9802dccdb6555d4209ac2e60875a011/Lib/inspect.py#L2423-L2488)But, some refactoring is required\n\n- `getargvalues()` only works with `frame` objects, but it does not work correctly with pos-only and kw-only parameters. Bug: [`inspect.getargvalues` does not work correctly for pos-only and kw-only arguments · Issue #107833 · python/cpython · GitHub](https://github.com/python/cpython/issues/107833) Can it be replaced with modern tooling? No, I propose adding `inspect.Signature.from_frame` method\n\nNotice: formatargvalues should also be deprecated, because the only way to use is together with getargvalues.\n\nThere was a reverted attempt to depracate them in 3.5\n\n- `getcallargs()` was documented as deprecated for a long time, it also has known bugs with pos-only params ([`inspect.getcallargs` does not raise `TypeError` for pos-only passed as keywords · Issue #107831 · python/cpython · GitHub](https://github.com/python/cpython/issues/107831)). Can it be replaced with modern tooling? Yes: `inspect.Signature.bind`\n\n- `getfullargspec()` is documented as\n\n > Note that [signature()](https://docs.python.org/3/library/inspect.html#inspect.signature) and [Signature Object](https://docs.python.org/3/library/inspect.html#inspect-signature-object) provide the recommended API for callable introspection, and support additional behaviours (like positional-only arguments) that are sometimes encountered in extension module APIs. This function is retained primarily for use in code that needs to maintain compatibility with the Python 2 inspect module API.\n\nIt has a rich history of deprecation / undeprecation:\n\n- Deprecated: https://github.com/python/cpython/issues/64637\n- Undeprecated: https://github.com/python/cpython/issues/71359\n- Suggested to be deprecated again: https://github.com/python/cpython/issues/76371\n\nMore history: https://github.com/python/cpython/issues/76371#issuecomment-1270007408\n\nIt is broken in a sense that it does not differentiate pos-only from pos-or-keyword parameters.\n\nCan it be replaced with modern tooling? Partially: `inspect.signature` has some differences. But, `getfullargspec()` uses `signature()` internally\n\n### Has this already been discussed elsewhere?\n\nI have already discussed this feature proposal on Discourse\n\n### Links to previous discussion of this feature:\n\nhttps://discuss.python.org/t/consider-deprecating-a-bunch-of-inspect-functions/31369\n\nCC @gpshead \n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-108902\n* gh-112236\n* gh-112279\n* gh-112314\n* gh-112639\n* gh-116537\n* gh-116559\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2023-09-05T10:20:18Z","url":"https://github.com/python/cpython/issues/108901"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:937c564c-1fdd-d7d4-8cec-6e7d7bccd123 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 84A4:38E318:347A66B:426CA72:6B0211D5 |
| html-safe-nonce | 3bb462bf5405c3e1cf0af4a50a40502d5e6694a02014589700bf809a55413c94 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NEE0OjM4RTMxODozNDdBNjZCOjQyNkNBNzI6NkIwMjExRDUiLCJ2aXNpdG9yX2lkIjoiOTIxNDg5MzY0ODY1MzcxNzk3MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e95d911915c7f47d8875794cda1e915f23b7c85cb22ad58f792d40fa40e7a659 |
| hovercard-subject-tag | issue:1881667694 |
| 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/108901/issue_layout |
| twitter:image | https://opengraph.githubassets.com/70f8e38e05e2d68d4c99d9a14977dc469aab5362a7ca374a5199769c02df3e1e/python/cpython/issues/108901 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/70f8e38e05e2d68d4c99d9a14977dc469aab5362a7ca374a5199769c02df3e1e/python/cpython/issues/108901 |
| og:image:alt | Feature or enhancement Proposal: I propose to provide modern alternatives to and deprecate these inspect members: getargs() undocumented helper used in getargvalues. It works with __code__ objects.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sobolevn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width