Perform a Python code review by first understanding what the change is meant to do, then checking correctness, tests, readability, security and performance, in that order, while letting automated tools (a formatter, a linter and a type checker) handle style. Leave specific, kind, actionable comments and approve once the change is safe to ship, not when it matches your personal taste.
A good review catches bugs early, spreads knowledge across the team and keeps the codebase consistent. This guide gives a repeatable checklist, Python-specific things to look for, and a tooling setup that removes the boring parts of review.
Read the pull request description, the linked issue and any design notes first. Knowing the goal lets you judge whether the change solves the right problem, not just whether the code runs.
Check that the pull request is small enough to review well. Changes over a few hundred lines hide bugs; ask the author to split them. Confirm that CI is green before you spend time on details, because failing tests or lint errors will change the code anyway.
Humans should not argue about whitespace or import order. Configure these tools in pyproject.toml and run them in CI and as pre-commit hooks:
| Concern | Common tool |
|---|---|
| Formatting | ruff format or Black |
| Linting, import order, simple bugs | Ruff (or Flake8 with plugins) |
| Static typing | mypy or pyright |
| Security issues | Bandit, pip-audit for dependencies |
| Tests and coverage | pytest with pytest-cov |
A minimal setup looks like this:
When these pass, the reviewer can spend attention on design and logic. PEP 8 is the baseline style guide, and a formatter enforces it for you.
Ask what happens with empty input, None, very large input, duplicate values, unexpected types and concurrent access. Look for classic Python pitfalls:
def add(item, items=[]).Exception or using a bare except: that hides real failures.== where is None is meant, or relying on truthiness when 0 or "" are valid values.with statement.Raise specific exceptions with useful messages, and check that error handling does not leak internal details to users.
Every behaviour change needs a test that would fail without the change. Check that tests cover the happy path, the edge cases above and the error paths. Prefer pytest with parametrization over copy-pasted tests, and avoid tests that depend on the current time, the network or execution order.
Coverage numbers are a hint, not a goal. A test that executes a line without asserting anything proves nothing.
Code is read far more often than written. Look for clear names, small functions that do one thing, type hints on public functions, and docstrings that explain why, not what. Prefer idiomatic Python: comprehensions for simple transformations, pathlib over string paths, f-strings, dataclasses or typing.NamedTuple for data holders, and enumerate or zip instead of index juggling.
Check the design too: does the change duplicate existing code, add a dependency that is not needed, or put logic in the wrong layer? Flag premature abstraction as readily as copy-paste.
Do not micro-optimise, but watch for obvious costs: repeated membership tests on a list (use a set), database queries inside loops, loading a whole file when iterating lines would do, and quadratic string concatenation.
For security, check that:
eval, exec, os.system or subprocess with shell=True.pickle on untrusted data, and YAML uses yaml.safe_load.Be specific, explain the reason and suggest a fix. Separate blocking problems from optional ideas, for example by prefixing small suggestions with nit:. Ask questions instead of making accusations, and praise good solutions. Reviewing the code, not the person, keeps feedback useful and the team willing to receive it.
Aim for under an hour per review, and review no more than a few hundred lines at a time. Quality drops quickly beyond that, so ask for smaller pull requests.
Only when the tooling cannot catch it. If you repeatedly comment on the same style issue, add a Ruff rule or formatter setting instead.
For new public functions in a typed codebase, yes. They document intent and let mypy or pyright catch bugs before runtime.
Approve when remaining comments are optional improvements and nothing blocks safe release. Mark blocking issues clearly and request changes only for those.
Understand the context, let tools handle formatting, linting, typing and security scans, and spend human time on correctness, tests, design and risk. Keep pull requests small, give specific and respectful feedback, and approve when the change is safe and maintainable.