| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
CPython's C functions receive the module as their first argument, so
PyCFunction.__self__ is the module and inspect strips the $module
parameter when building a Signature. A #[pyfunction] takes no such
argument, PyNativeFunction::zelf is None, and inspect has nothing to
strip, so the marker surfaced as a parameter that does not exist:
inspect.signature(len)
(module, /, obj) # was
(obj) # now
All 45 builtins shared with CPython carried it. Methods are unaffected;
their $self marker comes from func_sig and both branches now produce the
same string.
Assisted-by: Claude Code:claude-opus-5
Arguments bind through `FuncArgs::take_positional`, which pops from the
positional list and never consults the keyword map, so a #[pyfunction]
argument cannot be passed by name:
>>> len(obj=[1, 2])
TypeError
The generated signature omitted the `/` marker, so inspect reported those
parameters as POSITIONAL_OR_KEYWORD, contradicting the call above. Emit
the marker, except for `*args`/`**kwargs`, which cannot be followed by
`/`, and for empty parameter lists.
14 of the 45 builtins shared with CPython now report an identical
signature, up from 0.
Assisted-by: Claude Code:claude-opus-5
Arguments bound by a destructuring pattern, e.g.
fn round(RoundArgs { number, ndigits }: RoundArgs, ..)
have no name to report, and func_sig stringified the pattern verbatim:
>>> round.__text_signature__
'($module, RoundArgs { number, ndigits })'
That is not valid Python, so inspect.signature() raised "builtin has
invalid signature". Return None instead, which leaves
__text_signature__ unset and makes inspect raise "no signature found",
the same as for a CPython builtin that has no signature.
Affects round, sum, os.pathconf, binascii.b2a_base64 and
binascii.b2a_uu. Their docstrings are unchanged; only the signature
prefix is dropped.
Assisted-by: Claude Code:claude-opus-5
These parameters are positional-only, so their names only ever appear in
__text_signature__ and cannot be used at a call site. Naming them after
CPython makes the generated signatures directly comparable:
bin x -> number
ord string -> character
divmod a, b -> x, y
setattr attr -> name
delattr attr -> name
hasattr attr -> name
isinstance typ -> class_or_tuple
issubclass subclass,typ -> cls, class_or_tuple
aiter iter_target -> async_iterable
23 of the 45 builtins shared with CPython now report an identical
signature, up from 0 before this branch. The remainder need FromArgs to
report the parameters of its own structs, which is left for a follow-up.
Add extra_tests/snippets/builtin_signature.py covering the phantom
module parameter, the positional-only marker, the names above, and the
signature-less builtins.
Assisted-by: Claude Code:claude-opus-5
pydoc's summary line for time.time was "time(module)" because the generated signature carried a $module parameter that inspect could not strip. It now reads "time()", as the test expects. Assisted-by: Claude Code:claude-opus-5
test_snippets runs every snippet under CPython as well, and CPython does have Argument Clinic signatures for round and sum, so that block only holds for RustPython. Assisted-by: Claude Code:claude-opus-5
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: d4d5938c-456f-41b7-a1d8-d9c94ebe7a40 📥 CommitsReviewing files that changed from the base of the PR and between ce81d4d and 611744d. 📒 Files selected for processing (1)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review. 📝 Walkthrough WalkthroughBuiltin signature generation now supports missing signatures and positional-only formatting. Method generation preserves available documentation and emits no documentation when none exists. Builtin parameter names and signature tests were updated. ChangesBuiltin signature and documentation handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to 61174 This PR corrects builtin signature metadata and related tests without introducing a concrete merge-blocking correctness, security, availability, or deployment risk; no actionable merge-blocking risk remains after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant Builtins as Builtin definitions
participant Generator as Signature generator
participant Methods as Method generation
participant Inspect as inspect.signature
Builtins->>Generator: Provide Rust function signature
Generator-->>Methods: Return text signature or None
Methods->>Methods: Combine signature and source documentation
Methods-->>Inspect: Expose optional documentation and signature metadata
Inspect-->>Builtins: Bind positional-only and variadic parameters
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. ❤️ ShareComment @coderabbitai help to get the list of available commands. |
Sorry, something went wrong.
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [ ] lib: cpython/Lib/pydoc.py dependencies:
dependent tests: (5 tests)
Legend:
|
Sorry, something went wrong.
There was a problem hiding this comment.
great improvements, thanks!
Sorry, something went wrong.
The merge of main took ord's signature from this branch, which renamed the parameter to character, and its body from main, which rewrote ord to accept bytes and bytearray through a parameter named c. The body then referenced a name that no longer existed and the build failed. Assisted-by: Claude Code:claude-opus-5
Head branch was pushed to by a user without write access
#[pyfunction]/#[pymethod] derive __text_signature__ from the Rust parameter list, and a function that takes FuncArgs to check its own arity has no parameters to report, so func_sig emits "(*args, **kwargs)". Every builtin this branch rewrote that way - len, abs, hash, chr, callable, bin, ord, divmod, isinstance, issubclass and the rest of the 27 - stopped reporting the signature that RustPython#8512 had just made accurate: inspect.signature(len) (*args, **kwargs) # was (obj, /) Add `text_signature = "..."`, which overrides the derived parameter list, and give the affected builtins CPython's own, verified against CPython 3.14.7. round declares (number, ndigits=None) and so has a signature now, where before its destructuring pattern left it with none; builtin_signature.py keeps sum as the signature-less case and asserts round's instead. The derived signature is still used wherever no override is given, so genuinely variadic builtins such as breakpoint keep reporting (*args, **kwargs). Assisted-by: Claude:Claude Opus 5
| Back | FazBrowse Home | New Git URL |
Problem
RustPython's #[pyfunction]s generate a __text_signature__ that isn't comparable to CPython's. Of the 45 builtin functions RustPython shares with CPython 3.14, none reported an identical inspect.signature() before this PR:
Tools that rely on inspect.signature() (unittest.mock.autospec, pydoc, IDE completion) act on this bad metadata.
Scope
This PR fixes everything reachable by changing crates/derive-impl/src/util.rs's signature generator alone, without touching FromArgs or adding new types. The #[derive(FromArgs)] struct case is deliberately left out, so #8383 stays open after this merges.
What changed
Before / after
Measured across the 45 builtin functions RustPython and CPython 3.14 share:
The 22 that still differ fall into two groups that need different work.
CPython documents a signature we could match (13). Twelve of these hold their arguments in a type the signature generator can't see into: a #[derive(FromArgs)] struct (__import__, compile, eval, exec, open, pow, print, sorted, and round/sum, which now report no signature at all) or an OptionalArg whose default lives in the function body (format, input). The thirteenth, breakpoint, differs only because CPython names its keyword catch-all **kws and the generator hardcodes **kwargs for every FuncArgs function.
CPython has no signature at all, and RustPython reports one (9). __build_class__, anext, dir, getattr, iter, max, min, next and vars. Teaching FromArgs to report its parameters would not close this gap, since the generated signature is not what's wrong: matching CPython here means deciding to suppress a signature we are able to produce. test_autospec_on_bound_builtin_function stays expectedFailure for exactly this reason, via time.ctime.
Not in this PR
Two follow-ups would close most of the first group above:
The second group needs a separate decision about whether RustPython should suppress signatures CPython doesn't publish, which seems worth settling before either follow-up.
Two unrelated problems turned up while investigating, both out of scope here:
Test plan
Developed with assistance from Claude Code (claude-opus-5)
Summary by CodeRabbit
Bug Fixes
Tests