GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Reuse checked signatures for deque, timezone and type by youknowdot · Pull Request #9773 · RustPython/RustPython 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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| // timezone | ||
|
|
||
| /// timezone(offset, name=<unrepresentable>) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
dont' manually add docs
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
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__.
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:
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 complete name(...)\n--\n\n header supplies its own text signature."explicit_internal_doc_preserves_legacy_signatures → e.g. explicit_internal_doc_signature_is_kept.legacy signature should remain unrepresentable message → describe them as explicit internal-doc signatures.#9757 went through the same rename (legacy_signature → signature_from_flags) for the same reason.
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.
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.
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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
a6fadd3 to
847ee0b
Compare
Keep optional-group and CSV display signatures separate from argument binding. Validate explicit overrides against binding metadata in a const context and preserve legacy call behavior. Assisted-by: OpenAI Codex: model version not exposed
Assisted-by: OpenAI Codex:model version not exposed
Assisted-by: OpenAI Codex:model version not exposed
Assisted-by: OpenAI Codex:model version not exposed
Assisted-by: OpenAI Codex:model version not exposed
847ee0b to
632530b
Compare
Assisted-by: OpenAI Codex:model version not exposed
Requested changes must be addressed to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.