Review Python code for PEP compliance, type hints, and Pythonic patterns.
Reviews Python code for PEP compliance, type hints, and Pythonic patterns.
/plugin marketplace add KreativReason/merged-end-to-end-ai-dpp---e2e-cli/plugin install kreativreason-e2e-pipeline@kreativreason-marketplaceReview Python code for PEP compliance, type hints, and Pythonic patterns.
# Good: Full type hints
from typing import Optional, List
from dataclasses import dataclass
@dataclass
class User:
id: str
email: str
role: str
created_at: datetime
def get_users(
limit: int = 10,
offset: int = 0,
role: Optional[str] = None
) -> List[User]:
"""Fetch users with optional filtering."""
query = User.query
if role:
query = query.filter_by(role=role)
return query.limit(limit).offset(offset).all()
# Bad: No type hints
def get_users(limit=10, offset=0, role=None):
query = User.query
if role:
query = query.filter_by(role=role)
return query.limit(limit).offset(offset).all()
# Good: PEP 8 compliant
class UserService:
"""Service for user operations."""
def __init__(self, repository: UserRepository) -> None:
self._repository = repository
def create_user(self, email: str, password: str) -> User:
"""Create a new user with hashed password."""
hashed = hash_password(password)
return self._repository.create(email=email, password_hash=hashed)
# Good: Pattern matching
match response.status_code:
case 200:
return response.json()
case 404:
raise NotFoundError()
case _:
raise APIError(f"Unexpected status: {response.status_code}")
# Good: Structural pattern matching
match user:
case {"role": "admin", "department": dept}:
return f"Admin of {dept}"
case {"role": "user"}:
return "Regular user"
| Check | Description |
|---|---|
| Type hints | All public functions typed |
| PEP 8 | Style guide compliance |
| Docstrings | Functions documented |
| Import order | isort compliance |
| Security | No hardcoded secrets, SQL injection |
| Async patterns | Proper async/await usage |
{
"artifact_type": "python_review",
"status": "pass|warn|fail",
"data": {
"target": "PR #123",
"python_version": "3.11",
"type_checking": {
"mypy_compliant": true,
"coverage": "92%"
},
"findings": [
{
"id": "PY-001",
"severity": "medium",
"title": "Missing Type Hints",
"file": "app/services/report.py",
"line": 34,
"function": "generate_report",
"suggestion": "Add return type annotation"
},
{
"id": "PY-002",
"severity": "low",
"title": "PEP 8 Violation",
"file": "app/utils/helpers.py",
"line": 12,
"description": "Line too long (95 > 88 characters)",
"suggestion": "Break line or use black formatter"
}
],
"tooling_suggestions": [
"Run black for formatting",
"Run mypy --strict for type checking",
"Run ruff for linting"
]
}
}
from module import *You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.