Title: Malformed builtin __text_signature__ makes inspect.signature(len/sorted/open) raise ValueError · Issue #8383 · RustPython/RustPython · GitHub
Open Graph Title: Malformed builtin __text_signature__ makes inspect.signature(len/sorted/open) raise ValueError · Issue #8383 · RustPython/RustPython
X Title: Malformed builtin __text_signature__ makes inspect.signature(len/sorted/open) raise ValueError · Issue #8383 · RustPython/RustPython
Description: Summary inspect.signature() fails on common builtins (len, sorted, open, …) with ValueError: <...> builtin has invalid signature, where CPython returns a proper Signature. The cause is that the auto-generated __text_signature__ values ar...
Open Graph Description: Summary inspect.signature() fails on common builtins (len, sorted, open, …) with ValueError: <...> builtin has invalid signature, where CPython returns a proper Signature. The cause is that the aut...
X Description: Summary inspect.signature() fails on common builtins (len, sorted, open, …) with ValueError: <...> builtin has invalid signature, where CPython returns a proper Signature. The cause is that t...
Opengraph URL: https://github.com/RustPython/RustPython/issues/8383
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Malformed builtin __text_signature__ makes inspect.signature(len/sorted/open) raise ValueError","articleBody":"## Summary\n\n`inspect.signature()` fails on common builtins (`len`, `sorted`, `open`, …) with `ValueError: \u003c...> builtin has invalid signature`, where CPython returns a proper `Signature`. The cause is that the auto-generated `__text_signature__` values are malformed: they expose the Rust parameter names and omit the positional-only (`/`) and keyword-only (`*`) markers, so they are either rejected by `inspect` or semantically wrong.\n\n## Reproduction\n\n```python\nimport inspect\nprint(inspect.signature(len))\n# RustPython: ValueError: \u003cbuilt-in function len> builtin has invalid signature\n# CPython: (obj, /)\n```\n\nSame `ValueError` for `inspect.signature(sorted)` and `inspect.signature(open)`.\n\nThe underlying `__text_signature__` strings:\n\n| callable | RustPython | CPython 3.14 |\n|---|---|---|\n| `len` | `'($module, obj)'` | `'($module, obj, /)'` |\n| `abs` | `'($module, x)'` | `'($module, x, /)'` |\n| `sorted` | `'($module, iterable, opts)'` | `'($module, iterable, /, *, key=None, reverse=False)'` |\n| `open` | `'($module, args)'` | full signature with defaults |\n| `iter` | `'($module, iter_target, sentinel)'` | `None` |\n\nRustPython actually populates `__text_signature__` for *more* builtins than CPython, but the values are generated from the Rust function's parameters (`opts`, `args`, `iter_target`, …) and lack the `/` / `*` separators, so:\n\n- `inspect.signature` raises `ValueError` instead of returning a signature, and\n- where it would parse, the signature is wrong (e.g. `sorted` would show `(iterable, opts)` rather than `(iterable, /, *, key=None, reverse=False)`).\n\n## Context\n\nThis is a follow-up to #2410 (\"Builtin functions and methods lack a `.__text_signature__` property\"), which is closed — the attribute now exists, but its values do not match CPython and break `inspect.signature`.\n\nProducing fully accurate signatures for every builtin is a large effort (CPython hand-authors them via Argument Clinic), so a reasonable minimum would be that `inspect.signature()` returns *something* usable (or raises the same way CPython does for genuinely signature-less builtins) rather than `ValueError` on `len`/`sorted`/`open`.\n\n## Reference\n\nVerified against CPython 3.14.5.\n\n---\n\n*Investigated and drafted by Claude; reviewed before filing.*\n","author":{"url":"https://github.com/youknowone","@type":"Person","name":"youknowone"},"datePublished":"2026-07-26T07:23:35Z","url":"https://github.com/RustPython/RustPython/issues/8383"}
| 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:031b4436-c982-6b6c-90df-045ea44d6c9e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AA2E:3E4205:33A9B9C:45041F7:6B0201F1 |
| html-safe-nonce | 0d98cc369c3a2c2a607a508107d2499f9b18e41a7391916ce04c64f149695c0c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTJFOjNFNDIwNTozM0E5QjlDOjQ1MDQxRjc6NkIwMjAxRjEiLCJ2aXNpdG9yX2lkIjoiNjYyMDQ1NTc2NjU5Mzc2NTg3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 417830bfbedc82183e48a8aef45ad6f33f1ad02b36700b515c4c7d606349726f |
| hovercard-subject-tag | issue:4979577932 |
| 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/RustPython/RustPython/8383/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d95ff0e8911c7dca4cb696293997407f7207d8b6556b2b9e172fbddf60166f41/RustPython/RustPython/issues/8383 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d95ff0e8911c7dca4cb696293997407f7207d8b6556b2b9e172fbddf60166f41/RustPython/RustPython/issues/8383 |
| og:image:alt | Summary inspect.signature() fails on common builtins (len, sorted, open, …) with ValueError: <...> builtin has invalid signature, where CPython returns a proper Signature. The cause is that the aut... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | youknowone |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| 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