Skip to content

Stop generating a __text_signature__ that inspect cannot parse - #8681

Merged
youknowone merged 2 commits into
RustPython:mainfrom
leehanjeong:8383-invalid-signature
Sep 10, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
leehanjeong:8383-invalid-signature

Conversation

@leehanjeong

@leehanjeong leehanjeong commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

inspect.signature() raises ValueError: builtin has invalid signature for 99 method descriptors, because it parses __text_signature__ as Python source and two generated strings are not valid Python. Two unrelated causes, one commit each.

Callee was reported as a parameter. The interpreter supplies it the way it supplies vm, but only vm was filtered:

>>> object.__getstate__.__text_signature__
'(*args, **kwargs, callee)'          # a parameter cannot follow **kwargs

object.__getstate__ is the only #[pymethod] taking one today, and 95 types inherit it. infer_native_call_flags counted it as a fixed positional argument too, which FuncArgs happens to short-circuit today, so the call flags were right by accident.

maketrans named its first parameter from, a Python keyword. Argument Clinic spells it frm for the same reason, so bytes.maketrans and bytearray.maketrans now report (frm, to, /), which is what CPython reports. Both parameters are positional-only, so the name is documentation only.

Notes

Summary by CodeRabbit

  • Bug Fixes

    • Corrected native call signature and flag handling for functions that receive interpreter-supplied callee arguments.
  • Refactor

    • Updated internal parameter naming for byte and bytearray translation methods without changing their behavior.

The interpreter supplies `callee` the way it supplies `vm`, but only `vm`
was filtered, so the argument surfaced as a Python parameter and left a
string inspect cannot parse:

    >>> object.__getstate__.__text_signature__
    '(*args, **kwargs, callee)'
    >>> inspect.signature(object.__getstate__)
    ValueError: builtin has invalid signature

Filter it in `func_sig`, and in `infer_native_call_flags`, which counted
it as a fixed positional argument. `object.__getstate__` is the only
#[pymethod] taking one today, inherited by 95 types.

Assisted-by: Claude Code:claude-opus-5
`from` is a Python keyword, so the generated signature could not be
parsed:

    >>> bytes.maketrans.__text_signature__
    '(from, to, /)'
    >>> inspect.signature(bytes.maketrans)
    ValueError: builtin has invalid signature

CPython's Argument Clinic spells it `frm` for the same reason. Both
parameters are positional-only, so the name is documentation only.
`bytes.maketrans` and `bytearray.maketrans` now report what CPython
reports, `(frm, to, /)`.

Assisted-by: Claude Code:claude-opus-5
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: 68c57547-3f59-482b-84ac-7dc2fbe43fac

📥 Commits

Reviewing files that changed from the base of the PR and between 3fe1c32 and f462f64.

📒 Files selected for processing (3)
  • crates/derive-impl/src/util.rs
  • crates/vm/src/builtins/bytearray.rs
  • crates/vm/src/builtins/bytes.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The derive utility now excludes interpreter-supplied Callee arguments from call metadata. The maketrans methods rename a parameter from from to frm without changing behavior.

Changes

Native call and builtin cleanup

Layer / File(s) Summary
Interpreter-supplied argument handling
crates/derive-impl/src/util.rs
infer_native_call_flags and func_sig now skip typed arguments ending with Callee, in addition to &VirtualMachine arguments.
maketrans parameter renaming
crates/vm/src/builtins/bytearray.rs, crates/vm/src/builtins/bytes.rs
The first maketrans parameter is renamed from from to frm and passed through unchanged.

Priority: ➖ Normal

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to f462f

This fixes invalid generated builtin signatures and aligns bytes and bytearray maketrans parameter names with Python syntax without changing their behavior. No concrete current-head merge risk remains.

Suggested reviewers: youknowone, shaharnaveh

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preventing generation of invalid text_signature values that inspect cannot parse.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the z-ca-2026 Tag to track Contribution Academy 2026 label Sep 9, 2026
@leehanjeong
leehanjeong marked this pull request as ready for review September 9, 2026 15:17
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is a new feature to tell the function calling context. it seems we need to trim the convention more to avoid confusion. let's do it like this now.

@youknowone
youknowone merged commit c4fbc31 into RustPython:main Sep 10, 2026
29 checks passed
youknowone pushed a commit that referenced this pull request Sep 16, 2026
…8681)

* Leave Callee out of a generated __text_signature__

The interpreter supplies `callee` the way it supplies `vm`, but only `vm`
was filtered, so the argument surfaced as a Python parameter and left a
string inspect cannot parse:

    >>> object.__getstate__.__text_signature__
    '(*args, **kwargs, callee)'
    >>> inspect.signature(object.__getstate__)
    ValueError: builtin has invalid signature

Filter it in `func_sig`, and in `infer_native_call_flags`, which counted
it as a fixed positional argument. `object.__getstate__` is the only
#[pymethod] taking one today, inherited by 95 types.

Assisted-by: Claude Code:claude-opus-5

* Rename maketrans's first parameter to frm

`from` is a Python keyword, so the generated signature could not be
parsed:

    >>> bytes.maketrans.__text_signature__
    '(from, to, /)'
    >>> inspect.signature(bytes.maketrans)
    ValueError: builtin has invalid signature

CPython's Argument Clinic spells it `frm` for the same reason. Both
parameters are positional-only, so the name is documentation only.
`bytes.maketrans` and `bytearray.maketrans` now report what CPython
reports, `(frm, to, /)`.

Assisted-by: Claude Code:claude-opus-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

z-ca-2026 Tag to track Contribution Academy 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants