# PR Body Templates — Python

Python-specific PR body template variants. Read `${CLAUDE_PLUGIN_ROOT}/references/shared/pr-body-templates.md` first for the generic structure and writing guidelines.

**Key**: `codeflash compare` generates ready-to-paste markdown — E2E timing table, per-function breakdown, memory table (when available), improvement bars, and the "Generated by codeflash optimization agent" footer. Paste its output directly into the `{{CODEFLASH_COMPARE_OUTPUT}}` placeholder. The only thing the agent adds on top is `{{PLATFORM_DESCRIPTION}}` (machine specs + Python version), since `codeflash compare` does not include platform info.

---

## CPU / Data Structures / Async Variant

```markdown
{{SUMMARY_BULLETS}}

{{TECHNICAL_DETAILS}}

## Benchmark

### {{PLATFORM_DESCRIPTION}}

{{CODEFLASH_COMPARE_OUTPUT}}

<details>
<summary><b>Reproduce the benchmark locally</b></summary>

```bash
# Full comparison (timing + memory if --memory was used):
{{RUNNER}} -m codeflash compare {{BASE_REF}} {{HEAD_REF}} {{CODEFLASH_COMPARE_FLAGS}}

# Or manually with pytest-benchmark:
git checkout {{BASE_REF}}
{{RUNNER}} -m pytest {{BENCHMARK_PATH}} --benchmark-save=baseline

git checkout {{HEAD_REF}}
{{RUNNER}} -m pytest {{BENCHMARK_PATH}} --benchmark-compare=0001_baseline
```

</details>

{{CHANGELOG_SECTION}}

## Test plan

- [x] {{TEST_ITEM_1}}
- [x] {{TEST_ITEM_2}}
```

---

## Memory Variant

Use when `codeflash compare` is not available and you're profiling with memray directly. If `codeflash compare` IS available, use the CPU variant — its output already includes the memory table.

```markdown
{{SUMMARY_BULLETS}}

{{TECHNICAL_DETAILS}}

## Benchmark

### {{PLATFORM_DESCRIPTION}}

#### Memory

| Ref | Peak Memory | Allocations | Delta |
|:---|---:|---:|:---|
| `{{BASE_REF}}` (base) | {{BASE_PEAK}} | {{BASE_ALLOCS}} | |
| This PR (head) | {{HEAD_PEAK}} | {{HEAD_ALLOCS}} | {{MEMORY_DELTA}} |

---

*Generated by codeflash optimization agent*

<details>
<summary><b>Reproduce the benchmark locally</b></summary>

```python
{{COMPARE_MEMORY_SCRIPT}}
```

Or manually:

```bash
# Base
git checkout {{BASE_REF}}
{{RUNNER}} -m memray run --native --trace-python-allocators -o /tmp/base.bin {{BENCHMARK_SCRIPT_PATH}}
{{RUNNER}} -m memray stats /tmp/base.bin

# Head
git checkout {{HEAD_REF}}
{{RUNNER}} -m memray run --native --trace-python-allocators -o /tmp/head.bin {{BENCHMARK_SCRIPT_PATH}}
{{RUNNER}} -m memray stats /tmp/head.bin
```

</details>

{{CHANGELOG_SECTION}}

## Test plan

- [x] {{TEST_ITEM_1}}
- [x] {{TEST_ITEM_2}}
```

---

## Python-Specific Placeholders

| Placeholder | Description | Example |
|:---|:---|:---|
| `{{PLATFORM_DESCRIPTION}}` | Machine spec + Python version | `Azure Standard_D8s_v5 — 8 vCPU Intel Xeon Platinum 8473C, 32 GiB RAM, Python 3.12` |
| `{{CODEFLASH_COMPARE_OUTPUT}}` | Paste `codeflash compare` markdown output directly. Includes E2E table, per-function breakdown, memory table, improvement bars, and footer. | |
| `{{BASE_REF}}` / `{{HEAD_REF}}` | Git refs compared | `origin/main` / `codeflash/optimize` |
| `{{RUNNER}}` | Python runner from setup.md | `uv run python`, `python`, `poetry run python` |
| `{{BENCHMARK_PATH}}` | Path to pytest-benchmark test file | `tests/benchmarks/test_benchmark_quotes.py` |
| `{{CODEFLASH_COMPARE_FLAGS}}` | Extra flags for `codeflash compare`. `--memory` for memray profiling. Omit if timing-only. | `--memory` |
| `{{COMPARE_MEMORY_SCRIPT}}` | Full self-contained `compare_memory.py` script (memory variant only) | |
| `{{BASE_PEAK}}` / `{{HEAD_PEAK}}` | Peak memory from memray stats (memory variant only) | `72.0 MiB` / `47.0 MiB` |
| `{{BASE_ALLOCS}}` / `{{HEAD_ALLOCS}}` | Allocation count from memray stats (memory variant only) | `124` / `118` |
| `{{MEMORY_DELTA}}` | Memory change with indicator (memory variant only) | `-35%` |
