Title: Add inspect.signature support for more builtins · Issue #107161 · python/cpython · GitHub
Open Graph Title: Add inspect.signature support for more builtins · Issue #107161 · python/cpython
X Title: Add inspect.signature support for more builtins · Issue #107161 · python/cpython
Description: Feature or enhancement Like mentioned before for datetime classes, inspect.signature() also fails on many classes (and some functions) in builtins. However, this is not universal behaviour, as inspect.signature() works well with some cla...
Open Graph Description: Feature or enhancement Like mentioned before for datetime classes, inspect.signature() also fails on many classes (and some functions) in builtins. However, this is not universal behaviour, as insp...
X Description: Feature or enhancement Like mentioned before for datetime classes, inspect.signature() also fails on many classes (and some functions) in builtins. However, this is not universal behaviour, as insp...
Opengraph URL: https://github.com/python/cpython/issues/107161
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add inspect.signature support for more builtins","articleBody":"# Feature or enhancement\r\n\r\nLike [mentioned before](https://github.com/python/cpython/issues/88784) for `datetime` classes, `inspect.signature()` also fails on many classes (and some functions) in `builtins`. However, this is *not* universal behaviour, as `inspect.signature()` works well with some classes (and most functions) in `builtins`.\r\nThe functions and classes in `builtins` that `inspect.signature()` supports have a `str` `__text_signature__` pseudo-attribute, e.g.:\r\n```\r\n>>> divmod.__text_signature__\r\n'($module, x, y, /)'\r\n>>> complex.__text_signature__\r\n'(real=0, imag=0)'\r\n```\r\nThe proposed enhancement is to add the same `__text_signature__` to others:\r\n* Functions: `anext`, `breakpoint`, `dir`, `getattr`, `iter`, `max`, `min`, `next`, `vars`\r\n* Classes: `bool`, `filter`, `int`, `map`, `range`, `slice`, `str`, and many more, incl. all `Exception` classes\r\n\r\n# Pitch\r\n\r\nThis addition will help consistency and avoid confusion and the need for special-casing.\r\n\r\n## Example\r\nI ran into this when coding an [`arity()`](https://en.wikipedia.org/wiki/Arity) function using `inspect.signature().parameters`. My `arity()` works e.g. for `float` and `complex`, but fails for `int`, which was unexpected and confusing.\r\n\r\n## Beneficial side-effect\r\nLikely, this will also improve `help()` output, e.g.\r\n```\r\n>>> help(iter)\r\niter(...) \u003c\u003c\u003c signature missing\r\n Get an iterator from an object.\r\n```\r\n\r\n## Already available\r\nThis might seem challenging for some of the `builtins` functions and classes that have multiple signatures (e.g. `iter(iterable)` next to `iter(callable, sentinel)`). However, these are already available in the typeshed stub file, `builtins.pyi`.","author":{"url":"https://github.com/Dutcho","@type":"Person","name":"Dutcho"},"datePublished":"2023-07-23T21:54:17Z","url":"https://github.com/python/cpython/issues/107161"}
| 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:64b0ee80-1d30-43bf-6c2c-503407b348f1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AB62:15D703:106A74E:157254B:6B0006AF |
| html-safe-nonce | 873083a9a0823d915cdd74da2924914ffd398d2b5f397667cebe250127326734 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQjYyOjE1RDcwMzoxMDZBNzRFOjE1NzI1NEI6NkIwMDA2QUYiLCJ2aXNpdG9yX2lkIjoiNDYzNjA5NTYzNzkyMDY3OTU5OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cc108b6e4ad116dcaf4a23be20783ad546c83261695e0638e2fb22085756c559 |
| hovercard-subject-tag | issue:1817308894 |
| 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/107161/issue_layout |
| twitter:image | https://opengraph.githubassets.com/156dd466f452d15be468f8863bb74b438687817cc4c03c0bd97ca4f2a75ecc9e/python/cpython/issues/107161 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/156dd466f452d15be468f8863bb74b438687817cc4c03c0bd97ca4f2a75ecc9e/python/cpython/issues/107161 |
| og:image:alt | Feature or enhancement Like mentioned before for datetime classes, inspect.signature() also fails on many classes (and some functions) in builtins. However, this is not universal behaviour, as insp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Dutcho |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width