Title: Revert __signature__ to being a cache, remove string and callable support · Issue #116110 · python/cpython · GitHub
Open Graph Title: Revert __signature__ to being a cache, remove string and callable support · Issue #116110 · python/cpython
X Title: Revert __signature__ to being a cache, remove string and callable support · Issue #116110 · python/cpython
Description: Feature or enhancement Proposal: #100039 modified the behavior of __signature__ as used by the inspect.signature function : if the fields contains a Signature object, it is returned by the function (that doesn't change) if it contains No...
Open Graph Description: Feature or enhancement Proposal: #100039 modified the behavior of __signature__ as used by the inspect.signature function : if the fields contains a Signature object, it is returned by the function...
X Description: Feature or enhancement Proposal: #100039 modified the behavior of __signature__ as used by the inspect.signature function : if the fields contains a Signature object, it is returned by the function...
Opengraph URL: https://github.com/python/cpython/issues/116110
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Revert __signature__ to being a cache, remove string and callable support","articleBody":"# Feature or enhancement\r\n\r\n### Proposal:\r\n\r\n#100039 modified the behavior of `__signature__` as used by the inspect.signature function :\r\n- if the fields contains a Signature object, it is returned by the function (that doesn't change)\r\n- if it contains None, it is ignored (that doesn't change)\r\n- if it contains a string, it is converted to a signature (new)\r\n- if it contains a callable, it is called with no parameters and expected to return either a signature object or a string which will be treated as the above (new)\r\n- if it contains any other value, a TypeError is raised (this used to include strings and callables, it doesn't anymore)\r\n\r\n**As for strings :**\r\nThe `__text_signature__` attribute's purpose is to pass a string to inform the signature. It's also only used for C-written functions, and iirc there's no way to use it in pure python : I understand that, but if the ability to specify a text override of inspect.signature must happen, then it should go through `__text_signature__` and not `__signature__`.\r\n\r\n**As for callables :**\r\nThe Signature object qualifies, and the signature function inspects, callables. So, if when asked for the signature of a given callable you return another callable, it would make more sense to consider the second callable's signature as the signature of the first callable, than considering the second callable to _return_ the signature of the first. And why no parameters ? Why not pass the first callable as parameter ? Or the actual signature of the first callable ? That implementation raises a lot of questions of arbitrariness, which makes it a bad design in my opinion.\r\n\r\n**As for the purpose :**\r\nThe use case, which was adding signature overrides to Enums, does not require any change to the inspect module, in fact a perfectly good alternative implementation can be found in #115937. It should also make for a considerably faster execution.\r\n\r\nI suggest reverting these changes.\r\n\r\n### Links to previous discussion of this feature:\r\n\r\nThis was discussed in #115937 and #116086 in which it was advised to separate the question of the implementation from that of the documentation.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-116234\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Gouvernathor","@type":"Person","name":"Gouvernathor"},"datePublished":"2024-02-29T10:49:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/116110/cpython/issues/116110"}
| 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:0cb9e568-a87f-ad03-5143-95e80c2eec99 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B7E6:D741D:AF2A4:F0455:696962BB |
| html-safe-nonce | a483ef017e42fd75a62f8635f6ddc3e3b749ffe0a1982fcb2942cb45b5e813e8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCN0U2OkQ3NDFEOkFGMkE0OkYwNDU1OjY5Njk2MkJCIiwidmlzaXRvcl9pZCI6Ijc5MjU5MTE5MjEwMzE1MDI2NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4369a80a074b0d15ec3c5231b503757248ce822a7245dd0b5a769a00e65f3395 |
| hovercard-subject-tag | issue:2160963684 |
| 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/116110/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ca4d0b41611cd45da3ef48cd865023275bc0ce2929c1f92cf8aecb026d4bcffc/python/cpython/issues/116110 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ca4d0b41611cd45da3ef48cd865023275bc0ce2929c1f92cf8aecb026d4bcffc/python/cpython/issues/116110 |
| og:image:alt | Feature or enhancement Proposal: #100039 modified the behavior of __signature__ as used by the inspect.signature function : if the fields contains a Signature object, it is returned by the function... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Gouvernathor |
| hostname | github.com |
| expected-hostname | github.com |
| None | 48487c1ad776a7975b7132d95f4240ff3ae37cd5b8e3cb597102a4edb76738f1 |
| 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 | 669463fcc54773a88c1f5a44eef6b99a5504b9c7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width