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 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.
Reproduction
import inspect
print(inspect.signature(len))
# RustPython: ValueError: <built-in function len> builtin has invalid signature
# CPython: (obj, /)
Same ValueError for inspect.signature(sorted) and inspect.signature(open).
The underlying __text_signature__ strings:
| callable |
RustPython |
CPython 3.14 |
| len |
'($module, obj)' |
'($module, obj, /)' |
| abs |
'($module, x)' |
'($module, x, /)' |
| sorted |
'($module, iterable, opts)' |
'($module, iterable, /, *, key=None, reverse=False)' |
| open |
'($module, args)' |
full signature with defaults |
| iter |
'($module, iter_target, sentinel)' |
None |
RustPython 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:
- inspect.signature raises ValueError instead of returning a signature, and
- where it would parse, the signature is wrong (e.g. sorted would show (iterable, opts) rather than (iterable, /, *, key=None, reverse=False)).
Context
This 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.
Producing 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.
Reference
Verified against CPython 3.14.5.
Investigated and drafted by Claude; reviewed before filing.
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 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.
Reproduction
Same ValueError for inspect.signature(sorted) and inspect.signature(open).
The underlying __text_signature__ strings:
RustPython 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:
Context
This 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.
Producing 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.
Reference
Verified against CPython 3.14.5.
Investigated and drafted by Claude; reviewed before filing.