.claude/skills/writing-python/SKILL.md
Python コードの作成・レビュー時に適用する規約とベストプラクティス。 Pythonファイルの編集、Pythonプロジェクトのセットアップ、 pytest/ruff/mypyの実行時に自動で有効化される。
npx skillsauth add blackawa/dotfiles writing-pythonInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
必ず以下のツールを使用する。代替ツールは使わない。
| 用途 | ツール | 非推奨 | |------|--------|--------| | パッケージ管理 | uv | pip, poetry, pipenv | | Lint + Format | ruff | flake8, black, isort | | テスト | pytest | unittest | | 型チェック | mypy | - | | タスクランナー | Just | - |
# 依存関係
uv add <package> # 追加
uv add --dev <package> # dev依存追加
uv sync # 同期
uv lock # ロック更新
# 実行(直接 python, pytest を呼ばない)
uv run python <script>
uv run pytest -xvs # テスト
uv run ruff check --fix . # lint + autofix
uv run ruff format . # format
uv run mypy . # 型チェック
list[str], dict[str, int], str | Nonefrom __future__ import annotations は不要(Python 3.10+)Any 型は禁止。具体型、TypeVar、Protocolで代替する# type: ignore はテストコード内の希少なケースのみ許可# ✅ Good
def process_users(users: list[User], limit: int | None = None) -> list[Result]:
...
# ❌ Bad
def process_users(users, limit=None):
...
with 文)# ✅ 早期リターン
def get_user(user_id: str) -> User:
user = db.find(user_id)
if user is None:
raise UserNotFoundError(f"User {user_id} not found")
if not user.is_active:
raise InactiveUserError(f"User {user_id} is inactive")
return user
# ❌ ネスト地獄
def get_user(user_id: str) -> User:
user = db.find(user_id)
if user is not None:
if user.is_active:
return user
else:
raise InactiveUserError(...)
else:
raise UserNotFoundError(...)
except Exception: pass — エラーを握りつぶさないimport * によるワイルドカードインポート# ✅ Good
class PaymentError(Exception):
def __init__(self, amount: float, reason: str) -> None:
super().__init__(f"Payment of {amount} failed: {reason}")
self.amount = amount
self.reason = reason
try:
process_payment(order)
except PaymentGatewayTimeout as e:
logger.warning("Payment gateway timeout for order %s: %s", order.id, e)
raise PaymentError(order.total, "gateway timeout") from e
# ❌ Bad
try:
process_payment(order)
except Exception:
pass
tests/ ディレクトリtest_<振る舞い>_<条件> の形式@pytest.fixture でセットアップを共有する@pytest.mark.parametrize で網羅的にテストするclass TestCalculatePrice:
def test_returns_unit_price_without_tax(self) -> None:
result = calculate_price(total=100.0, quantity=10, tax_rate=0.0)
assert result == 10.0
def test_raises_on_zero_quantity(self) -> None:
with pytest.raises(ValueError, match="quantity must be positive"):
calculate_price(total=100.0, quantity=0, tax_rate=0.0)
@pytest.mark.parametrize("total,qty,tax,expected", [
(100, 10, 0.0, 10.0),
(100, 10, 0.1, 11.0),
(50, 5, 0.2, 12.0),
])
def test_multiple_scenarios(self, total: float, qty: int, tax: float, expected: float) -> None:
assert calculate_price(total, qty, tax) == pytest.approx(expected)
myproject/
├── src/myapp/
│ ├── __init__.py
│ ├── api/
│ ├── models/
│ ├── services/
│ └── utils/
├── tests/
│ ├── conftest.py
│ ├── unit/
│ └── integration/
├── pyproject.toml
└── README.md
[project]
name = "myapp"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = []
[dependency-groups]
dev = ["pytest>=8.0", "ruff>=0.8", "mypy>=1.0"]
[tool.ruff]
line-length = 100
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "I", "N", "W", "B", "C4", "UP"]
[tool.pytest.ini_options]
testpaths = ["tests"]
[tool.mypy]
strict = true
development
X(Twitter)の特定投稿URLから原文を直接取得するスキル。 fxtwitter API(APIキー不要・無料)を使用し、ロングポスト(記事形式)の全文取得にも対応。 以下のようなリクエストで発動する: 「この投稿を取得」「ツイートの内容」「このURLの投稿を見せて」 「このXの投稿を読んで」「このツイートを取得して」。 X/TwitterのURLが含まれるメッセージで、検索ではなく特定投稿の内容取得が目的の場合に使う。 x-ai-search との棲み分け: - 検索(キーワードで複数投稿を探す)→ x-ai-search - 特定投稿の取得(URLやIDで1件取得)→ x-tweet-fetch
development
TypeScript / JavaScript コードの作成・レビュー時に適用する規約とベストプラクティス。 .ts, .tsx, .js, .jsx ファイルの編集、Node.js/Deno プロジェクトのセットアップ、 vitest/biome/tsc の実行時に自動で有効化される。
business
Slackメッセージの作成・送信時に適用する規約とベストプラクティス。 slack_send_message / slack_send_message_draft の実行時に自動で有効化される。 「Slackで連絡して」「Slackに投稿して」「スレッドに返信して」 といった発言があれば、このスキルを使うこと。
business
社内向けの提案・決裁依頼テキストの作成時に適用する構成テンプレートとベストプラクティス。 「提案書を書いて」「決裁依頼を作って」「稟議を書いて」「承認を取りたい」 「〜を導入したい」「〜の予算を取りたい」「〜の増額を依頼したい」 といった発言があれば、このスキルを使うこと。 Slack / メール / ドキュメントいずれの媒体にも対応する。