review-python
2
总安装量
2
周安装量
#63090
全站排名
安装命令
npx skills add https://github.com/nesnilnehc/ai-cortex --skill review-python
Agent 安装分布
qoder
2
kilo
2
gemini-cli
2
antigravity
2
github-copilot
2
codex
2
Skill 文档
Skill: Review Python
Purpose
Review code in Python for language and runtime conventions only. Do not define scope (diff vs codebase) or perform security/architecture analysis; those are handled by scope and cognitive skills. Emit a findings list in the standard format for aggregation. Focus on type hints, exception handling, async/await patterns, context managers, dependency management, and testability.
Use Cases
- Orchestrated review: Used as the language step when review-code runs scope -> language -> framework -> library -> cognitive for Python projects.
- Python-only review: When the user wants only language/runtime conventions checked (e.g. after adding a new Python file).
- Pre-PR Python checklist: Ensure type hints, exception handling, and async patterns are correct.
When to use: When the code under review is Python and the task includes language/runtime quality. Scope (diff vs paths) is determined by the caller or user.
Behavior
Scope of this skill
- Analyze: Python language and runtime conventions in the given code scope (files or diff provided by the caller). Do not decide scope; accept the code range as input.
- Do not: Perform scope selection (diff vs codebase), security review, or architecture review; do not review non-Python files for Python-specific rules unless explicitly in scope.
Review checklist (Python dimension only)
- Type hints: Use
typingmodule for complex types, avoidAnywhere possible, useOptional[T]overT | Nonefor Python <3.10, proper use ofUnion,List,Dict,Callable, and generic type hints. - Exception handling: Catch specific exceptions, avoid bare
except:, useraise ... fromfor exception chaining, avoid swallowing exceptions without logging, proper use oftry/finally. - Async/await: Proper use of
async defandawait, avoid blocking calls in async functions, proper exception handling in async context, use ofasyncio.gather,asyncio.create_taskfor concurrency. - Context managers: Use
withstatement for resource management, implement__enter__/__exit__or use@contextmanager, avoid manual open/close. - Dependency management: Pin dependencies in
requirements.txtorpyproject.toml, avoidimport *, use virtual environments, proper use ofsys.pathmanipulation. - Mutable defaults: Avoid mutable default arguments (e.g.
def foo(a=[]):), useNoneand initialize inside function. - Naming conventions: Follow PEP8 (snake_case for functions/variables, PascalCase for classes, SCREAMING_SNAKE_CASE for constants).
- Testability: Avoid global state, use dependency injection, mock external services, avoid tight coupling.
Tone and references
- Professional and technical: Reference specific locations (file:line). Emit findings with Location, Category, Severity, Title, Description, Suggestion.
Input & Output
Input
- Code scope: Files or directories (or diff) already selected by the user or by the scope skill. This skill does not decide scope; it reviews the provided Python code for language conventions only.
Output
- Emit zero or more findings in the format defined in Appendix: Output contract.
- Category for this skill is language-python.
Restrictions
- Do not perform security, architecture, or scope selection. Stay within Python language and runtime conventions.
- Do not give conclusions without specific locations or actionable suggestions.
- Do not review non-Python code for Python-specific rules unless the user explicitly includes it (e.g. embedded code snippets).
Self-Check
- Was only the Python language/runtime dimension reviewed (no scope/security/architecture)?
- Are type hints, exception handling, async patterns, context managers, and testability covered where relevant?
- Is each finding emitted with Location, Category=language-python, Severity, Title, Description, and optional Suggestion?
- Are issues referenced with file:line?
Examples
Example 1: Mutable default argument
- Input:
def foo(items=[]): - Expected: Emit a finding for mutable default argument; suggest using
Noneand initializing inside. Category = language-python.
Example 2: Bare except
- Input:
except: pass - Expected: Emit a finding to catch specific exceptions; reference the bare except clause. Category = language-python.
Example 3: Async blocking call
- Input:
async def fetch(): requests.get(url)inside an async function. - Expected: Emit a finding to use
aiohttporhttpx; reference the blocking call. Category = language-python.
Edge case: Mixed Python and SQL
- Input: Python file with embedded SQL strings for database queries.
- Expected: Review only Python conventions (type hints, exception handling). Do not emit SQL-injection findings; that is for review-security or review-sql.
Appendix: Output contract
Each finding MUST follow the standard findings format:
| Element | Requirement |
|---|---|
| Location | path/to/file.ext (optional line or range). |
| Category | language-python. |
| Severity | critical | major | minor | suggestion. |
| Title | Short one-line summary. |
| Description | 1-3 sentences. |
| Suggestion | Concrete fix or improvement (optional). |
Example:
- **Location**: `utils/helpers.py:42`
- **Category**: language-python
- **Severity**: major
- **Title**: Mutable default argument
- **Description**: Using a list as default argument leads to shared state across calls.
- **Suggestion**: Use `def foo(items=None):` and initialize with `if items is None: items = []`.