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

  1. Zero, empty and None are told apartif rate: skips a real 0.0; test is 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
  2. Defaults are not shared by accidentA default is evaluated only once.[2] Use None, or field(default_factory=…) in a dataclass.[3] Sentry’s queued: datetime = timezone.now() gave every object the same time.
    IonWarp Code Review checks this
  3. hash() never leaves the processString hashes are salted with a random value per process,[4] so a cache key built on hash() misses on every other worker. Use hashlib.
    IonWarp Code Review checks this
  4. Order is not assumed between two callszip(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
  5. Optional objects are checked before useSentry read organization_context.member.has_global_access where member is None for API-token requests.
    IonWarp Code Review checks this
  6. Exceptions are specific and loggedNo bare except: and no except Exception: pass. Log with context, re-raise what the code can’t handle, and open files and connections in a with block so they close on an error.
    IonWarp Log & Errors checks this

Django and data

  1. 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
  2. No query runs inside a loopLoad related rows with select_related or prefetch_related, and give every list read a limit.
    IonWarp API Performance checks this
  3. 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

  1. Untrusted data never reaches pickle, eval or a shellpickle can run code while loading,[6] and shell=True needs every argument quoted.[7] Use json, yaml.safe_load and argument lists.
    IonWarp Security Review checks this
  2. SQL uses parametersNo f-strings or % formatting into raw() or cursor.execute(); pass the values as parameters.
    IonWarp Security Review checks this

Types, tests and docs

  1. 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
  2. Tests really exercise the changeA Sentry test patched time.sleep to 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
  3. 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]

  1. Low · Logic · Sentry benchmark copy, PR 3

    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

  2. Low · Data · Sentry benchmark copy, PR 3

    Cache keys built with hash() don’t match across worker processes, so the cache can’t be cleared.

    The check: hash() never leaves the process

  3. Medium · Concurrency · Sentry PR 77754

    queued: datetime = timezone.now() runs once, when the class is defined, so every object shares that time.

    The check: Defaults are not shared by accident

  4. High · Logic · Sentry benchmark copy, PR 1

    A paginator slices a Django queryset with a negative offset, which Django refuses.

    The check: Querysets are sliced forward only

  5. High · Logic · Sentry benchmark copy, PR 1

    API-token requests have no member, so member.has_global_access raises.

    The check: Optional objects are checked before use

  6. Low · Logic · Sentry benchmark copy, PR 5

    zip(error_ids, events.values()) assumes the lookup returns rows in the order asked.

    The check: Order is not assumed between two calls

  7. Medium · Test gap · Sentry PR 93824

    The test patched time.sleep, then called it to wait for the flusher: the wait never happened.

    The check: Tests really exercise the change

  8. Low · Docs · Sentry PR 80168

    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]

Known Python issues each AI reviewer caught
ReviewerCaught (Sentry)ShareF1, all 50 PRsFalse alarms, all 50 PRs
Qodo v2Caught: 20 of 33Share: 61%F1, all 50 PRs: 58.5%False alarms: 79
IonWarp · DeepSeek V4.1 FlashCaught: 17 of 33Share: 52%F1, all 50 PRs: 49.2%False alarms: 78
Greptile v4.1Caught: 15 of 33Share: 45%F1, all 50 PRs: 51.1%False alarms: 78
CodeRabbitCaught: 15 of 33Share: 45%F1, all 50 PRs: 42.1%False alarms: 194
Cursor BugbotCaught: 13 of 33Share: 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.

Python review tools and the checks they cover
ToolWhat it checksChecklist line
RuffWhat 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
mypyWhat it checks: Static types from your hints[8]Checklist line: Type hints match
BanditWhat it checks: Common security issues in Python code[13]Checklist line: Untrusted data, SQL
Coverage.pyWhat it checks: Which lines the tests ran[14]Checklist line: Tests exercise the change
IonWarpWhat it checks: Logic, callers and missing changes on each pull requestChecklist line: Python traps, Django and data
The IonWarp app’s Bugs screen in the sample Acme workspace: 16 bugs caught on pull requests, 1 escaped, 3 issues open
What the IonWarp app showsThe Bugs screen, in the sample workspace: each bug its agents caught on a pull request, next to the ones that got past.

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 code

FAQ

Quick answers

What should I check in a Python code review?

Zeros and empty strings read as missing, shared mutable defaults, hash() leaving the process, order assumed between calls, unchecked optional objects, broad excepts, negative queryset slices, queries in loops, unsafe pickle or shell calls, and tests that fail without the change.

Does a Python code review need PEP 8?

The code should follow it, but a reviewer shouldn’t enforce it by hand. Run Ruff in CI to lint and format, and keep style comments out of the review.

What are the best Python code review tools?

Ruff for lint and format, mypy for types, Bandit for security patterns, Coverage.py for untested lines, and an AI reviewer for logic and callers. A person still approves.

How do you review Python code quickly?

Ask for one change per pull request with commits that say what they do, read the description, ask how it was tested, then read the diff for the traps on this page: zero versus None, shared defaults, hash(), order assumptions and unchecked optionals.

Is there a Python code review checklist on GitHub?

Copy the template on this page into .github/pull_request_template.md, and GitHub shows it on every new pull request.

More checklists

More checklists

Get the Python traps flagged on every PR.

Get started

See pricing

By , Co-founder, IonWarp. Published .

Co-founder of Segment (acquired by Twilio, 2020). Builds IonWarp at Winding AI, Inc. See something wrong? Send us a correction.