Resolve test_inspect bytecode parity gaps#7926
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRefactors compile-time scope classification to use explicit CompilerScope variants, maps specific class-related dunder identifiers to unknown symbol scope, consolidates class dunder emission via ChangesScope and Dunder Name Resolution Refactoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Sorry, something went wrong.
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/inspect.py dependencies:
dependent tests: (90 tests)
Legend:
|
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/codegen/src/compile.rs`:
- Around line 20926-20955: The assertion is too weak because it only checks for
any Instruction::StoreDeref without verifying the deref targets; update the
third assert to resolve the StoreDeref's target index (from unit.arg/OpArg as
used elsewhere) back into the closure capture name (using class_code.freevars or
the appropriate captured-names table) and assert that the resolved name is
exactly "__firstlineno__" (i.e. check the deref slot maps to "__firstlineno__"
rather than just any StoreDeref), keeping the existing error message format and
using the same symbols: class_code.instructions, Instruction::StoreDeref,
unit.arg/OpArg, and class_code.freevars to locate the code to change.
- Around line 3261-3262: The fallback that maps underscore-prefixed identifiers
to SymbolScope::Unknown is too broad—replace the single check
name.starts_with('_') with a whitelist of the compiler-generated synthetic
dunders introduced in this patch: e.g., match exact names via a constant set
(SYNTHETIC_NAMES.contains(name)) and/or prefix list
(SYNTHETIC_PREFIXES.iter().any(|p| name.starts_with(p))) and only map those to
SymbolScope::Unknown; keep the rest of identifiers unchanged. Update the code
around the existing branch that returns SymbolScope::Unknown (the expression
using name and SymbolScope::Unknown) to use this whitelist logic and add or
adjust tests to cover both synthetic dunders and normal user names.
- Line 6717: Replace the call to self.store_name("__classdictcell__") with an
unconditional class-local store like you do for "__classdict__" (emit
Instruction::StoreDeref or the equivalent direct store-deref bytecode) so the
name is always written into the class namespace regardless of global/nonlocal
declarations; likewise find the parallel location handling "__classcell__" and
change its self.store_name("__classcell__") to the same direct StoreDeref-style
emission. Locate these in compile.rs near the class-creation handling (the site
where "__classdict__" is already handled with Instruction::StoreDeref) and
ensure both special slots bypass store_name() and are stored unconditionally
into the class namespace.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 6fdca45e-5dbf-4384-91c9-e0ba1346cec8
⛔ Files ignored due to path filters (1)
Lib/test/test_inspect/test_inspect.pyis excluded by!Lib/**
📒 Files selected for processing (1)
crates/codegen/src/compile.rs
Sorry, something went wrong.
62b081b
into
RustPython:main
May 19, 2026
Summary by CodeRabbit
Refactor
Tests