スキル一覧に戻る
physics91

python-reviewer

by physics91

Claude Code hooks를 활용하여 세션 컴팩션 시 AGENTS.md 컨텍스트를 자동으로 보존/복원하는 플러그인

0🍴 0📅 2025年12月29日
GitHubで見るManusで実行

SKILL.md


name: python-reviewer description: | WHEN: General Python code review, PEP8 compliance, type hints, Pythonic patterns WHAT: PEP8/style check + Type hint validation + Pythonic idioms + Error handling + Documentation WHEN NOT: FastAPI → fastapi-reviewer, Django → django-reviewer, Data science → python-data-reviewer

Python Reviewer Skill

Purpose

Reviews Python code for style, idioms, type safety, and best practices.

When to Use

  • Python code review requests
  • PEP8 compliance check
  • Type hint review
  • "Is this Pythonic?" questions
  • General Python project review

Project Detection

  • requirements.txt, pyproject.toml, setup.py, setup.cfg
  • .py files in project
  • __init__.py module structure

Workflow

Step 1: Analyze Project

**Python Version**: 3.11+
**Package Manager**: pip/poetry/uv
**Type Checking**: mypy/pyright
**Linter**: ruff/flake8/pylint
**Formatter**: black/ruff

Step 2: Select Review Areas

AskUserQuestion:

"Which areas to review?"
Options:
- Full Python review (recommended)
- PEP8/Style compliance
- Type hints and safety
- Error handling patterns
- Performance and idioms
multiSelect: true

Detection Rules

PEP8 & Style

CheckRecommendationSeverity
Line > 88 charsBreak line or refactorLOW
Missing docstringAdd module/function docstringMEDIUM
Import order wrongUse isort or ruffLOW
Inconsistent namingsnake_case for functions/varsMEDIUM
# BAD: Inconsistent naming
def getUserName(userId):
    pass

# GOOD: PEP8 naming
def get_user_name(user_id: int) -> str:
    pass

Type Hints

CheckRecommendationSeverity
Missing return typeAdd -> ReturnTypeMEDIUM
Any type overuseUse specific typesMEDIUM
Optional without None checkAdd None handlingHIGH
Missing generic typesUse list[T], dict[K,V]LOW
# BAD: No type hints
def process(data):
    return data.get("name")

# GOOD: Full type hints
def process(data: dict[str, Any]) -> str | None:
    return data.get("name")

Pythonic Idioms

CheckRecommendationSeverity
Manual loop for listUse list comprehensionLOW
if x == TrueUse if xLOW
Manual dict iterationUse .items(), .keys(), .values()LOW
try/except passHandle or log exceptionHIGH
Mutable default argUse None defaultCRITICAL
# BAD: Mutable default argument
def append_to(item, target=[]):
    target.append(item)
    return target

# GOOD: None default
def append_to(item, target: list | None = None) -> list:
    if target is None:
        target = []
    target.append(item)
    return target

# BAD: Manual loop
result = []
for x in items:
    if x > 0:
        result.append(x * 2)

# GOOD: List comprehension
result = [x * 2 for x in items if x > 0]

Error Handling

CheckRecommendationSeverity
Bare exceptCatch specific exceptionsHIGH
except ExceptionBe more specificMEDIUM
No logging in exceptAdd loggingMEDIUM
Missing finallyAdd cleanup if neededLOW
# BAD: Bare except
try:
    process()
except:
    pass

# GOOD: Specific exception with logging
try:
    process()
except ValueError as e:
    logger.error(f"Invalid value: {e}")
    raise
except IOError as e:
    logger.warning(f"IO error: {e}")
    return None

Modern Python (3.10+)

CheckRecommendationSeverity
Union[X, Y]Use X | YLOW
Optional[X]Use X | NoneLOW
Dict, List from typingUse dict, list builtinLOW
No match statementConsider match for complex branchingLOW
# OLD: typing imports
from typing import Optional, Union, List, Dict

def func(x: Optional[int]) -> Union[str, None]:
    pass

# MODERN: Built-in syntax (3.10+)
def func(x: int | None) -> str | None:
    pass

# Match statement (3.10+)
match status:
    case 200:
        return "OK"
    case 404:
        return "Not Found"
    case _:
        return "Unknown"

Response Template

## Python Code Review Results

**Project**: [name]
**Python**: 3.11 | **Tools**: ruff, mypy, pytest

### Style & PEP8
| Status | File | Issue |
|--------|------|-------|
| LOW | utils.py:45 | Line exceeds 88 characters |

### Type Hints
| Status | File | Issue |
|--------|------|-------|
| MEDIUM | service.py:23 | Missing return type annotation |

### Pythonic Idioms
| Status | File | Issue |
|--------|------|-------|
| CRITICAL | models.py:12 | Mutable default argument |

### Error Handling
| Status | File | Issue |
|--------|------|-------|
| HIGH | api.py:67 | Bare except clause |

### Recommended Actions
1. [ ] Fix mutable default arguments
2. [ ] Add specific exception handling
3. [ ] Add type hints to public functions
4. [ ] Run ruff --fix for style issues

Best Practices

  1. Type Hints: Use for all public APIs
  2. Docstrings: Google or NumPy style
  3. Error Handling: Specific exceptions, always log
  4. Testing: pytest with fixtures
  5. Tooling: ruff (lint+format), mypy (types)

Integration

  • fastapi-reviewer: FastAPI specific patterns
  • django-reviewer: Django specific patterns
  • python-data-reviewer: Pandas/NumPy patterns
  • security-scanner: Python security checks

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です