[codex] Add evidence-backed native Python idiom advice#4
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6455254275
ℹ️ 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".
| if binding is not None: | ||
| name, collection_kind = binding | ||
| collection_bindings[name] = collection_kind | ||
| continue | ||
| if _manual_collection_loop_kind(statement, collection_bindings): |
There was a problem hiding this comment.
Invalidate accumulator bindings after name reassignment
This pass keeps collection_bindings forever once a name is initialized to []/{}/set(), so later loops can be flagged even after that name is reassigned to a non-empty or unrelated value. For example, acc = []; acc = preload(); for x in xs: acc.append(x) is reported as a manual accumulator loop even though it is no longer a simple empty-accumulator pattern. That produces incorrect PY-AGENT-R011 advice and undermines the rule’s stated conservative behavior.
Useful? React with 👍 / 👎.
715e6cb to
55182ad
Compare
55182ad to
cbc46af
Compare
Summary
PY-AGENT-R011so agents prefer comprehensions, generator expressions, built-ins, or named iterator pipeline helpers when public functions spell boilerplate loopsPolicy rationale
This keeps ruff/mypy/pytest as the normal tool substrate and uses the harness for the gap those tools do not own: compact reasoning-tree advice for LLM code repair. The new rule is parser-first and advisory; explicit loops remain valid for effects, complex state, debugging, or measured performance work.
Evidence sources
match/case, comprehensions,itertools, built-ins,dataclasses, andtypingValidation
uv run --group test ruff format --check src tests docsuv run --group test ruff check src testsuv run --group test pytest tests/unit/python_lang_parser/test_control_flow.py tests/unit/harness/test_agent_algorithm_policy.py tests/unit/harness/test_policy_contract.py tests/unit/harness/test_agent_policy.py tests/unit/harness/test_parser_boundary_contract.py -quv run --group test pytest tests -quv run --group test python-project-harness .uv run --group test python-project-harness --agent-snapshot .uv buildgit diff --check