Guides / Code review checklist
Python code review checklist: what to check in a Python PR
A Python code review checklist adds Python’s own traps to the usual checks: a 0 or empty string read as missing, a default built once and shared, hash() that changes between processes, and Django querysets that refuse negative slices. Each comes from a real Sentry pull request.
The checks every language shares are on the code review checklist; this page is the Python layer, built from the 33 known issues in 10 Sentry pull requests in our benchmark.[1]
Checked
What should a Python code review check?
A Python code review should check 14 things in four groups: Python’s traps, Django and data, security, and types, tests and docs. Style is left to Ruff, so none of the 14 is about formatting.
Python traps
- Zero, empty and None are told apart
if rate:skips a real0.0; testis None. Sentry’s upsampling skipped a sample rate of 0.0 this way, and a.get("timestamp")check treated 0 as missing.[1]
IonWarp Code Review checks this - Defaults are not shared by accidentA default is evaluated only once.[2] Use
None, orfield(default_factory=…)in a dataclass.[3] Sentry’squeued: datetime = timezone.now()gave every object the same time.
IonWarp Code Review checks this hash()never leaves the processString hashes are salted with a random value per process,[4] so a cache key built onhash()misses on every other worker. Usehashlib.
IonWarp Code Review checks this- Order is not assumed between two calls
zip(ids, results.values())pairs the wrong rows when results come back in another order or with a key missing. Look values up by key.
IonWarp Code Review checks this - Optional objects are checked before useSentry read
organization_context.member.has_global_accesswherememberis None for API-token requests.
IonWarp Code Review checks this - Exceptions are specific and loggedNo bare
except:and noexcept Exception: pass. Log with context, re-raise what the code can’t handle, and open files and connections in awithblock so they close on an error.
IonWarp Log & Errors checks this
Django and data
- Querysets are sliced forward onlyDjango does not support negative indexing on a QuerySet;[5] a Sentry paginator passed a negative offset and raised.
IonWarp Code Review checks this - No query runs inside a loopLoad related rows with
select_relatedorprefetch_related, and give every list read a limit.
IonWarp API Performance checks this - Migrations are safe on big tablesA schema change on a large table is announced before deploy, a new filter has an index, and a data migration handles rows that don’t match.
IonWarp Code Review checks this
Security
- Untrusted data never reaches pickle, eval or a shell
picklecan run code while loading,[6] andshell=Trueneeds every argument quoted.[7] Usejson,yaml.safe_loadand argument lists.
IonWarp Security Review checks this - SQL uses parametersNo f-strings or
%formatting intoraw()orcursor.execute(); pass the values as parameters.
IonWarp Security Review checks this
Types, tests and docs
- Type hints match and mypy passesmypy checks the hints statically;[8] a changed return type changes its callers in the same pull request.
IonWarp Code Review checks this - Tests really exercise the changeA Sentry test patched
time.sleepto return at once, then slept to wait for a worker. Run the test against the old code once: it should fail.
IonWarp Code Review checks this - Docstrings match the codeA Sentry docstring still promised a list after the method began returning a dict.
IonWarp Docs Review checks this
Which Python bugs reach real pull requests?
The Python bugs that reach real pull requests are ordinary logic bugs Python makes easy to write: the answer key for 10 Sentry pull requests lists 33 issues a reviewer should catch, and these eight show the patterns.[1]
if client_sample_rate:treats 0.0 as missing, so a sample rate of zero is never set.The check: Zero, empty and None are told apart
Cache keys built with
hash()don’t match across worker processes, so the cache can’t be cleared.The check:
hash()never leaves the processqueued: datetime = timezone.now()runs once, when the class is defined, so every object shares that time.The check: Defaults are not shared by accident
A paginator slices a Django queryset with a negative offset, which Django refuses.
The check: Querysets are sliced forward only
API-token requests have no member, so
member.has_global_accessraises.The check: Optional objects are checked before use
zip(error_ids, events.values())assumes the lookup returns rows in the order asked.The check: Order is not assumed between two calls
The test patched
time.sleep, then called it to wait for the flusher: the wait never happened.The check: Tests really exercise the change
The docstring says a list of results; the method now returns a dict keyed by group.
The check: Docstrings match the code
How many Python bugs do AI code reviewers catch?
AI code reviewers caught at most 20 of the 33 known Python issues in 10 Sentry pull requests: Qodo v2 caught the most, and IonWarp caught 17. None caught them all, so the checklist stays with a person.[9][10]
| Reviewer | Caught (Sentry) | Share | F1, all 50 PRs | False alarms, all 50 PRs |
|---|---|---|---|---|
| Qodo v2 | Caught: 20 of 33 | Share: 61% | F1, all 50 PRs: 58.5% | False alarms: 79 |
| IonWarp · DeepSeek V4.1 Flash | Caught: 17 of 33 | Share: 52% | F1, all 50 PRs: 49.2% | False alarms: 78 |
| Greptile v4.1 | Caught: 15 of 33 | Share: 45% | F1, all 50 PRs: 51.1% | False alarms: 78 |
| CodeRabbit | Caught: 15 of 33 | Share: 45% | F1, all 50 PRs: 42.1% | False alarms: 194 |
| Cursor Bugbot | Caught: 13 of 33 | Share: 39% | F1, all 50 PRs: 51.4% | False alarms: 56 |
Caught means the judge matched a reviewer’s comment to a known issue; false alarms are comments that matched none, over all 50 pull requests. Every row and PR is on the Code Review benchmark.
Which tools automate a Python code review?
Ruff, mypy, Bandit and Coverage.py cover style, types, known-insecure calls and untested lines, so the reviewer spends the time on logic.
| Tool | What it checks | Checklist line |
|---|---|---|
| Ruff | What it checks: Lint and format, PEP 8 style;[11] 10 to 100 times faster than Flake8 and Black, its docs say[12] | Checklist line: None: style is off the list |
| mypy | What it checks: Static types from your hints[8] | Checklist line: Type hints match |
| Bandit | What it checks: Common security issues in Python code[13] | Checklist line: Untrusted data, SQL |
| Coverage.py | What it checks: Which lines the tests ran[14] | Checklist line: Tests exercise the change |
| IonWarp | What it checks: Logic, callers and missing changes on each pull request | Checklist line: Python traps, Django and data |

Is there a Python code review checklist template?
Yes, a Python code review checklist template is below: paste it into .github/pull_request_template.md under the general checklist.[15]
## Python review
- [ ] 0, "" and [] are not read as None (use `is None`)
- [ ] No mutable default; dataclasses use default_factory
- [ ] No hash() in a key that leaves the process
- [ ] No order assumed between two calls (zip, dict values)
- [ ] Optional objects checked before attribute access
- [ ] No bare except; errors logged with context
- [ ] Querysets sliced forward only
- [ ] No query runs inside a loop
- [ ] Migrations safe on big tables
- [ ] No pickle, eval or shell=True on untrusted data
- [ ] SQL passes parameters
- [ ] mypy passes; changed types change their callers
- [ ] A test fails without the change
- [ ] Docstrings match the codeSources
Sources checked : each one says the day we read it.
- Martian on GitHub, code-review-benchmark, Core set: 50 pull requests and their answer key, revision e616e849 (MIT), read .
- Python docs, Default argument values: “The default value is evaluated only once”, read .
- Python docs, dataclasses: field(default_factory=…), read .
- Python docs, object.__hash__: str and bytes hashes are salted per process, read .
- Django docs, Limiting QuerySets: negative indexing is not supported, read .
- Python docs, pickle: “The pickle module is not secure”, read .
- Python docs, subprocess: security considerations for shell=True, read .
- mypy, mypy documentation: a static type checker for Python, read .
- IonWarp, Code Review benchmark, pull request by pull request (release 2026-10-12), read .
- Winding Labs on GitHub, ai-code-review-benchmark: every row, pull request and verdict (CC BY 4.0), read .
- Python, PEP 8: Style Guide for Python Code, read .
- Astral, Ruff: an extremely fast Python linter and code formatter, read .
- PyCQA, Bandit: find common security issues in Python code, read .
- Coverage.py, Coverage.py: code coverage for Python, read .
- GitHub Docs, Creating a pull request template for your repository, read .

