Remove private comprehension flags - #8537
Conversation
Why: extend_namedexpr_scope() already propagates assignment-expression targets and records DEF_GLOBAL or DEF_NONLOCAL in comprehension scopes. ASSIGNED_IN_COMPREHENSION remained only for conflict checks. Its private bit overlaps CPython's packed LOCAL scope bit. Changes: - Register assignment-expression targets as ordinary assignments. - Detect later target conflicts from existing declaration flags. Assisted-by: Codex:gpt-5.6-sol
Why: ITER duplicates the DEF_LOCAL and DEF_COMP_ITER facts already recorded for comprehension targets. Its private bit also overlaps CPython's packed scope field. Changes: - Use those flags for rebinding checks and local restoration around inlined comprehensions. Assisted-by: Codex:gpt-5.6-sol
Why: Assignment-expression diagnostics exposed the mangled keys used for symbol-table lookup. CPython reports identifiers as written in source. Changes: - Use source names in both comprehension conflict diagnostics. - Enable test_named_expression_invalid_mangled_class_variables. Assisted-by: Codex:gpt-5.6-sol
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe code generator now represents comprehension iterators with ChangesComprehension Symbol Analysis
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change preserves comprehension conflict behavior, keeps inlined-comprehension handling equivalent, and corrects class-mangled diagnostics while removing redundant internal flags. The listed validation passes, so no actionable merge-blocking risk remains beyond normal checks and review. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] test: cpython/Lib/test/test_named_expressions.py (TODO: 1) dependencies: dependent tests: (no tests depend on named_expressions) Legend:
|
ShaharNaveh
left a comment
There was a problem hiding this comment.
TYSM!!!
I wanted to remove these for so long
Summary
ASSIGNED_IN_COMPREHENSIONandITERflags in favor of existing definition flags.Rationale
ASSIGNED_IN_COMPREHENSIONandITERduplicate facts already represented by the existing definition flags.They also occupy bit positions reserved for packed scope information.
Removing these private flags makes that range available for scope packing without losing the comprehension conflict checks.
CPython reference
CPython 3.14.7 handles both conflict directions using existing flags:
symtable_add_def_helper()rejects an iterator target already markedDEF_GLOBALorDEF_NONLOCAL, then records valid targets withDEF_COMP_ITER.symtable_extend_namedexpr_scope()rejects a named-expression target already markedDEF_LOCAL | DEF_COMP_ITER, otherwise propagatingDEF_GLOBALorDEF_NONLOCALinto the comprehension scope.The inlined-comprehension path is unchanged: every iterator target marked with
ITERwas alreadyDEF_LOCAL, so checkingDEF_LOCALalone selects the same locals for save/restore.Additionally, this PR fixes a small diagnostic bug found while updating these checks: lookup still uses the mangled key, while errors now show the identifier as written in the source. This enables the existing mangled-name diagnostic test.
Validation
Passed pre-commit, workspace and C-API tests, and all 74
test_named_expressionstests.Follow-up
A follow-up PR will build on this change to enable more
test_symtabletests.AI assistance
Codex (GPT-5.6 Sol) was used to investigate the symbol-table control flow, compare it with CPython, and implement this change. I reviewed the diff and the validation results above.
Summary by CodeRabbit