← ClaudeAtlas

python-devlisted

Use when the user asks to implement, refactor, test, debug, or review Python code, pytest/unittest behavior, typing, ruff/mypy issues, packaging, Pydantic models, or Python runtime errors.
iamtatsuki05/dotfiles · ★ 0 · AI & Automation · score 56
Install: claude install-skill iamtatsuki05/dotfiles
# Python開発スキル Pythonコードの実装、テスト、デバッグ、リファクタリングを効率的に行うためのガイド。 ## 実装前の必須確認 **pyproject.tomlを必ず確認する。** プロジェクトのコーディング規約(ruff, mypy設定等)に従う。 確認項目: - `[tool.ruff]`: line-length, quote-style, indent-style - `[tool.ruff.lint]`: select, ignore(有効/無効なルール) - `[tool.ruff.format]`: quote-style(シングル/ダブル) - `[tool.mypy]`: python_version, disallow_untyped_defs - `[tool.pytest.ini_options]`: テスト設定 - Python バージョンと既存記法。Python 3.12+ 構文は、対象プロジェクトが対応している場合だけ使う - 既存の依存、例外設計、テストヘルパー、型スタイル `pyproject.toml` がない場合は、`setup.cfg`、`tox.ini`、`requirements*.txt`、`uv.lock`、`poetry.lock`、既存コードのスタイルを確認する。Pydantic は既に採用されている、または要件に合う場合に使い、単純なデータ構造へ不用意に導入しない。 ## コーディング規約 ### 基本スタイル ```python # Python 3.12+のジェネリクス記法 def process_items[T](items: list[T], predicate: Callable[[T], bool]) -> list[T]: return [item for item in items if predicate(item)] # 型エイリアス type JsonValue = dict[str, Any] | list[Any] | str | int | float | bool | None # Pydantic BaseModel(原則こちらを使用) from pydantic import BaseModel, Field class Config(BaseModel): name: str value: int enabled: bool = True class User(BaseModel): id: int name: str = Field(min_length=1) email: str | None = None model_config = {'frozen': True} # イミュータブル ``` ### エラーハンドリング ```python # エラーメッセージは変数に代入してからraise(ruff EM101/EM102対策) def validate(data: dict[str, Any]) -> None: if 'required_field' not in data: msg = 'required_field is missing' raise ValueError(msg) # カスタム例外 class ValidationError(Exception): pass ```