Repository navigation
Reuse checked signatures for deque, timezone and type - #9773
youknowdot wants to merge 5 commits into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
|
|
||
| // timezone | ||
|
|
||
| /// timezone(offset, name=<unrepresentable>) |
youknowone
left a comment
There was a problem hiding this comment.
The mechanism looks right: has_internal_doc_signature follows find_signature + skip_signature in Objects/typeobject.c (the doc must start with name(, the scan looks for )\n--\n\n, and it gives up at a blank line). These four objects get their text signatures from hand-written docstring headers in CPython as well. A few things should change before merging, though.
Observed before → after
Before: a build of 45a012cda (main at the time). After: the values asserted in this PR's snippet, which match CPython 3.15.
| object | __text_signature__ before |
after (= CPython) | inspect.signature |
|---|---|---|---|
deque |
None |
'([iterable[, maxlen]])' |
ValueError both |
deque.index |
'($self, needle, start=0, stop=<unrepresentable>, /)' |
'($self, value, [start, [stop]])' |
ValueError both |
timezone |
None |
'(offset, name=<unrepresentable>)' |
ValueError both |
type.__dict__['__prepare__'] |
'($type, name, bases, /, **kwds)' |
'($cls, name, bases, /, **kwds)' |
(type, …) → (cls, …) |
In practice this changes raw metadata only. The only inspect-visible difference is the receiver name of the unbound __prepare__.
1. Drop "legacy" from the naming; one comment is factually wrong
The feature is "an explicit internal-doc signature in the docstring is used as-is", and has_internal_doc_signature already says that. "Legacy" in the title, branch, code comment, test name and snippet comment does not describe it:
- The comment in
signature.rs, "Explicit Clinic headers cover legacy signatures that are not Python parameter lists", is wrong for__prepare__:($cls, name, bases, /, **kwds)is an ordinary parameter list. Only the deque headers use optional groups. Something like: "A doc that starts with a completename(...)\n--\n\nheader supplies its own text signature." explicit_internal_doc_preserves_legacy_signatures→ e.g.explicit_internal_doc_signature_is_kept.- Snippet comment "Legacy Clinic headers …" and the
legacy signature should remain unrepresentablemessage → describe them as explicit internal-doc signatures. - PR title → e.g. "Honor explicit internal-doc signatures for deque, timezone and type.prepare".
#9757 went through the same rename (legacy_signature → signature_from_flags) for the same reason.
2. The header is used implicitly and never checked against the Rust binding
Any /// doc that happens to be header-shaped now silently replaces the generated signature, and nothing checks the hand-written header against the real arguments. The drift is already there: deque.index binds needle in Rust, while the header says value. The displayed text is correct today, but a later change to the Rust signature would go unnoticed.
#9757 takes the opposite approach: an explicit #[pyfunction(signature_from_flags)] opt-in, plus const assertions that reject a mismatched arity at compile time. CPython does not validate hand-written headers either, so this is not a parity bug. It is still inconsistent within RustPython. Please consider at least a const check that the header's positional arity agrees with the binding metadata, or an explicit opt-in so the override cannot happen by accident.
3. Docs are now split between two sources
Because a /// doc overrides the crates/doc DB entry, the bodies of these four docstrings are now hard-coded in Rust, and regenerating crates/doc/src/data.inc.rs will no longer update them. crates/doc/generate.py stores only __doc__, which has the header stripped. A broader fix would be to have the generator also capture __text_signature__. That can be a follow-up, but it should be acknowledged here.
4. Conflict with #9757
Both PRs append to crates/vm/src/function/signature.rs and to the end of extra_tests/snippets/builtin_signature.py, so whichever lands second needs a rebase.
— commented by Claude
a6fadd3 to
847ee0b
Compare
847ee0b to
632530b
Compare
|
Status check after #9758 (merged 2026-11-15, receivers moved out of
As agreed, the override work is the last piece of the text-signature series. — commented by Claude |
Validate receiver markers from the macro item kind and keep only explicit Python arguments in the const binding checks. Share Clinic-style overrides through FromArgs instead of repeating them on cloned methods. Assisted-by: Codex:unavailable
ce81228 to
f69a767
Compare
Keep the field-option list contiguous and describe the shared argument-spec override in its own paragraph, fixing strict Clippy doc-lazy-continuation diagnostics. Assisted-by: Codex:unavailable
f69a767 to
700b160
Compare
Replace map plus unwrap_or_default with the equivalent map_or_else expression to satisfy Clippy 1.100 while keeping Rust 1.99 compatibility and the generated token stream unchanged. Assisted-by: Codex:unavailable
Generate Clinic NULL defaults without text signature overrides, while rejecting unnamed constructor metadata. Assisted-by: OpenAI Codex:model version not exposed
Use the actual RustPython#9756 shared override, validate receivers at macro expansion, and keep timezone on the generated NULL-default path. Preserve centralized documentation. Assisted-by: OpenAI Codex:model version not exposed
700b160 to
f51d264
Compare
Consolidated into #9756
At the user's request, all commits and tests from this PR are now included unchanged in #9756 at the same combined head
f51d264b2228321f444a10ddc4d97e9ac42826b0. This PR is closed only to keep one active PR; its review discussion and original commits are preserved. The description below records this PR's implementation and validation before consolidation.Summary
This is a dependent follow-up to #9756. Current head
f51d264b2228321f444a10ddc4d97e9ac42826b0is stacked on the actual #9756 heade30a3bddbc79044cadabe36c378aa038a2c99c1c, with #9758's receiver changes already in the underlying main. The two follow-up commits distinguish declared omitted defaults from unknown defaults and reuse checked argument signatures for class metadata.rustpython-docdatabase. No copied Rust docstrings or implicit docstring-header bypass remains.FromArgs::TEXT_SIGNATUREfor initializer/constructor class metadata instead of adding another class-only override mechanism. Class signatures have no receiver marker; method/classmethod markers are checked by the common macro-time validation.DefaultRepr::Unrepresentable) from an unknown default (DefaultRepr::Unknown). This letstimezoneobtain(offset, name=<unrepresentable>)through ordinary signature generation, without a timezone override. Unknown defaults and unnamed leaf metadata remain rejected by the class representability check./. Apply explicit overrides only todeque,deque.index, andtype.__prepare__.type.__prepare__; unknown binding metadata remains rejected. Actual argument conversion and dispatch are unchanged.type.__prepare__ignoring arbitrary arguments and returning a fresh namespace.CPython 3.15 basis
_collectionsmodule.c: deque constructor and index explicitly use Argument Clinic@text_signatureoverrides._datetimemodule.c:datetime.timezone.__new__is Clinic-generated withname: unicode = NULL, displayed as<unrepresentable>.typeobject.c:type_prepareignores its arguments; its manually declared method header publishes$cls, name, bases, /, **kwds.Validation
Verified on 2026-11-17:
map_or_elselint correction and this PR's validator selection.builtin_signature.pysnippet passed again after the latest rebase.AI assistance
OpenAI Codex assisted with review, implementation, and validation.