Skip to content

Match CPython docstring indentation cleanup - #10161

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:align-docstring-indent-with-cpython
Dec 4, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:align-docstring-indent-with-cpython

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Match the indentation step in CPython 3.15.2's _PyCompile_CleanDoc: after tab expansion, strip only ASCII spaces from the first line and remove a common ASCII-space margin from subsequent lines. Unlike inspect.cleandoc, the compiler should leave non-ASCII whitespace and escaped carriage returns intact. Return the expanded string directly when there is no indentation to remove.

The change covers module, function, and class docstrings from both source and Python AST input, at optimization levels 0–2. The comparison against CPython covers 360 observations; 120 mismatches before the patch, none after. UTF-8 errors for surrogate-bearing docstrings remain separate, and the Ruff pin and Lib are unchanged.

Linux: 800 codegen tests, codegen Clippy with warnings denied, git hooks, and the new compile snippet section passed. The selected standard suite passed on both runtimes (13 CPython; 10 RustPython plus 3 CPython-only skips). Six standard compiler docstring vectors were also exercised via compile. Full suites, other platforms and performance were not verified locally.

Refs #9852.

Expand tabs before stripping ASCII spaces, use only non-blank lines after the first to derive the common margin, and preserve other leading whitespace. Reuse the expanded string when it is already clean.

Refs: RustPython#9852

Assisted-by: Codex:GPT-6.2
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@youknowone
youknowone marked this pull request as ready for review December 4, 2026 02:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T02:23:22.397645Z 79b854f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@youknowone
youknowone merged commit 3150828 into RustPython:main Dec 4, 2026
19 of 20 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79b854f1bd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let mut lines = doc.split('\n');
let first_line = lines.next().unwrap_or_default();

// Find the minimum indentation among non-blank lines after the first.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the still-valid indentation comments

The root AGENTS.md says “Do not delete or rewrite existing comments” unless they are factually wrong or contradict the new code. The removed explanation that a blank line contains only spaces (or is empty), along with the original first-pass and subsequent-line comments, remains accurate for this implementation. Preserve those comments instead of deleting or editorially rephrasing them as part of the indentation fix.

AGENTS.md reference: AGENTS.md:L99-L99

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants