2.2 KiB
2.2 KiB
Pre-Submit Self-Review — Python
Python-specific checks for the pre-submit review. Read ${CLAUDE_PLUGIN_ROOT}/references/shared/pre-submit-review.md first for the language-agnostic checklist.
Resource Ownership — Python Patterns
# Find all callers of a function you modified
git diff <base>..<branch> --name-only | xargs grep -n "function_name("
# For each caller: does it use the object after the call?
Watch for:
delon objects passed as parameters.close()on file handles, images, or connections that the caller may still reference- Context manager changes (
withblocks) that change resource lifetime - Early returns that skip cleanup of caller-owned resources
Concurrency — Python Patterns
asyncio.run()from existing loop: Never callasyncio.run()in code that may already be in an async context. Useasyncio.get_event_loop().run_in_executor()or check for a running loop first.- Module-level caches and globals:
dict,list, and other mutable objects at module scope are shared across threads in WSGI/ASGI servers. Usethreading.Lockorasyncio.Lockas appropriate. .pyccontamination: After reverting changes, stale.pycfiles can mask regressions. Delete__pycache__directories if you suspect stale bytecode.
Feature Flags & Alternate Paths
Check for Python-specific conditional paths that your tests might miss:
if os.environ.get(...)— environment-driven feature flagstry: import fast_lib except: import slow_lib— conditional imports- Monkey-patching consumers (common in test frameworks)
__init__.pyre-exports that may expose different implementations
# Find conditional paths in modified files
grep -n "os.environ\|importlib\|__import__\|monkey" <modified-files>
Type Safety
If the codebase uses type hints:
- Did a container type change (e.g.,
list→set) break iteration order guarantees? - Did a return type change (e.g., generator vs list)?
- Run
mypyorpyrightif the project uses them — checkpyproject.tomlfor type checker config.
Caller Discovery
# Find all callers of modified functions
grep -rn "function_name(" --include="*.py" .