# Python Code Review Review {{input}} for code quality, correctness, and best practices. ## Types and Style - Add type hints on all function signatures (PEP 484); use `from __future__ import annotations` for forward refs - Follow PEP 8: snake_case for functions/variables, PascalCase for classes, UPPER_CASE for constants - Avoid mutable default arguments (`def f(x=[])` is a classic bug — use `None` and set inside) - Prefer f-strings over `.format()` or `%` formatting ## Error Handling - Catch specific exceptions, not bare `except:` or `except Exception:` - Use context managers (`with`) for all file I/O, locks, and DB connections - Never suppress exceptions silently; at minimum log them with context - Distinguish between recoverable errors (return/raise) and programming errors (assert) ## Reliability - Handle edge cases: empty sequences, None inputs, zero denominators, empty strings - Avoid shared mutable state in module scope - For I/O-bound work prefer async or threading; for CPU-bound work prefer multiprocessing - Validate all config and environment variables at startup ## Security - No secrets or PII in logs, exception messages, or tracebacks exposed to users - Parameterise all DB queries — no f-string interpolation in SQL - Sanitise file paths; avoid `os.system()` / `subprocess` with user-controlled strings - Avoid `pickle` for untrusted data; prefer `json` or `msgpack` ## Code Quality - Functions should do one thing; < 30 lines each - No dead code, `# TODO` left unaddressed, or commented-out blocks - Tests use pytest; cover happy path and key error conditions --- List findings as **Critical** (security/data loss/crashes) -> **Major** (bugs/wrong behaviour) -> **Minor** (style/improvements). Cite each location and suggest the concrete fix.