Skip to content

[codex] Add evidence-backed native Python idiom advice#4

Merged
GTrunSec merged 5 commits intomainfrom
codex/pythonic-policy-evidence
May 7, 2026
Merged

[codex] Add evidence-backed native Python idiom advice#4
GTrunSec merged 5 commits intomainfrom
codex/pythonic-policy-evidence

Conversation

@GTrunSec
Copy link
Copy Markdown
Contributor

@GTrunSec GTrunSec commented May 7, 2026

Summary

  • add an evidence note that ties official Python guidance, mature GitHub project practice, and harness policy scope together
  • extend parser-owned function control-flow facts with simple manual collection and predicate loop signals
  • add advisory PY-AGENT-R011 so agents prefer comprehensions, generator expressions, built-ins, or named iterator pipeline helpers when public functions spell boilerplate loops

Policy 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

  • PEP 20 / PEP 8
  • Python docs for match/case, comprehensions, itertools, built-ins, dataclasses, and typing
  • GitHub source/config review of pydantic, pytest, httpx, and black

Validation

  • uv run --group test ruff format --check src tests docs
  • uv run --group test ruff check src tests
  • uv 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 -q
  • uv run --group test pytest tests -q
  • uv run --group test python-project-harness .
  • uv run --group test python-project-harness --agent-snapshot .
  • uv build
  • git diff --check

@GTrunSec GTrunSec marked this pull request as ready for review May 7, 2026 01:33
Copy link
Copy Markdown

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

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: 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".

Comment thread src/python_lang_parser/_control_flow.py Outdated
Comment on lines +255 to +259
if binding is not None:
name, collection_kind = binding
collection_bindings[name] = collection_kind
continue
if _manual_collection_loop_kind(statement, collection_bindings):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@GTrunSec GTrunSec force-pushed the codex/pythonic-policy-evidence branch 2 times, most recently from 715e6cb to 55182ad Compare May 7, 2026 01:59
@GTrunSec GTrunSec force-pushed the codex/pythonic-policy-evidence branch from 55182ad to cbc46af Compare May 7, 2026 02:25
@GTrunSec GTrunSec merged commit 0c72bea into main May 7, 2026
1 check passed
@GTrunSec GTrunSec deleted the codex/pythonic-policy-evidence branch May 7, 2026 03:12
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.

1 participant