Skip to content

Fix module docstring global name resolution - #9095

Merged
youknowone merged 2 commits into
RustPython:mainfrom
teddygood:fix-module-docstring-global
Oct 15, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
teddygood:fix-module-docstring-global

Conversation

@teddygood

@teddygood teddygood commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor
  • Closes #xxxx

One of checkbox below must be checked.

  • I did not use AI to write the code of this patch.
  • This PR follows our AI policy

Summary

compile_program stored the module docstring with a hard-coded StoreName, so a global __doc__ declaration in a nested function was ignored. Any other name in the same position follows the declaration.

src = '"module doc"\nx = 1\ndef f():\n    global __doc__, x\n'
g, loc = {}, {}
exec(compile(src, "<demo>", "exec"), g, loc)
print("x:", "x" in g, "x" in loc)
print("__doc__:", "__doc__" in g, "__doc__" in loc)

Before:

x: True False
__doc__: False True

After (same as CPython 3.15):

x: True False
__doc__: True False

The docstring is now stored through store_name, like every other module-level assignment. Without such a declaration the emitted instruction is unchanged.

AI assistance

Written with Claude (Opus 5.5), reviewed by a human before submission.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed module docstrings being stored in the wrong namespace when a nested function declares global __doc__.
    • Module docstrings now follow normal name-resolution behavior, including when compilation uses optimization.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8f2e6f95-b1fb-4d62-ad33-b4cfad4a239e
📥 Commits

Reviewing files that changed from the base of the PR and between 11b9773 and d9998e3.

📒 Files selected for processing: 1
  • extra_tests/snippets/syntax_doc.py

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

📝 Walkthrough

Module docstring storage now uses normal name resolution. Compiler and snippet tests cover global and local storage, nested declarations, optimization levels, and class docstrings.

Changes: Module docstring name resolution

Layer / File(s) Summary
Resolve module docstring stores
crates/codegen/src/compile.rs, extra_tests/snippets/syntax_doc.py
The compiler resolves the module __doc__ store through store_name. Tests check global versus local storage, nested global __doc__ declarations, optimization levels, and class docstrings.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: youknowone

Merge Risk: ⚪ Minimal · up to d9998

The change makes module docstrings honor a nested global doc declaration, and the added tests cover the expected cases. No merge-blocking issues were found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 and concisely describes the main change: correcting module docstring global name resolution.
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 a new PR
  • 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

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 Oct 13, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T11:39:44.670343Z d9998e3 New commits
ℹ️ 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.

@teddygood

Copy link
Copy Markdown
Contributor Author

oh I just saw the pr you mentioned. Sorry if you were already working on this. Please let me know if there's any overlap with your work.

@youknowone

Copy link
Copy Markdown
Member

@teddygood This PR is mentioned as seperated independent patch. Please go ahead, thanks!

Assisted-by: Claude Code:claude-opus-5-5
@teddygood
teddygood force-pushed the fix-module-docstring-global branch from b3ea04e to 11b9773 Compare October 15, 2026 04:27
@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.
Credits must be used to enable repository wide code reviews.

@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!

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.

let's add this test to extra_tests/snippets/syntax_doc.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved it into syntax_doc.py, thanks!

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

@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: d9998e3369

ℹ️ 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".

src_global = '"module doc"\ndef f():\n global __doc__\n'
code, g, loc = run_split(src_global)
ops = opnames(code)
assert "STORE_GLOBAL" in ops, ops

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 Remove the prohibited test-logic additions

This adds a new assertion, and the surrounding regression block adds new test logic and data, to extra_tests/snippets/syntax_doc.py. The repository rules explicitly forbid modifying test assertions, logic, or data and state that only expectedFailure decorator changes are acceptable, so this test block must be removed rather than landed with the Rust fix.

AGENTS.md reference: AGENTS.md:L275-L279

Useful? React with 👍 / 👎.

@youknowone
youknowone merged commit e01021b into RustPython:main Oct 15, 2026
8 checks passed
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