モダンなPythonの型ヒント、Protocolによる構造的部分型、および堅牢なコードのための型安全なパターンを実装します。
- GitHubスター
- 81
- ファイル
- 9
- 最終コミット
- 2026年11月7日
- ライセンス
- MIT
- 許可されたツール
- 2
python-typing-ops skillは何をしますか
python-typing-opsはAgent Skillsです。 モダンなPythonの型ヒント、Protocolによる構造的部分型、および堅牢なコードのための型安全なパターンを実装します。.
skillのSKILL.mdから生成された要約。
python-typing-ops skill について
このSKILLは、安全でドキュメント化されたコードベースを構築する開発者向けに、モダンなPythonの型ヒントと構造的部分型のパターンを実装することを可能にします。型注釈、ジェネリクス、およびProtocolを介した構造的部分型を適用するための包括的なツールセットを提供し、コードの信頼性を確保します。エージェントがこのSKILLをロードすると、TypeVar、TypedDict、Literal型などの高度な機能を使用して、コードの生成やリファクタリングを行うことができます。
このSKILLは、Union型を含むPython 3.10以降の構文、およびSelfやTypeVarTupleといったPython 3.11以降の特定のパターンをサポートしています。また、mypyやpyrightなどの型チェッカーの設定と実行を支援し、コードの整合性を検証します。これらのパターンを活用することで、開発者は基本的な注釈を超えて、型絞り込みのためのTypeGuardや、柔軟なインターフェース定義のための構造的部分型といった複雑なロジックを実装できます。これにより、静的解析を通じてランタイムエラーの削減を目指すすべての人にとって不可欠なツールとなります。
エージェントができること
- 1構造的部分型の実装特定のメソッドを持つ任意のオブジェクトを関数に渡せるように、Protocolを定義します。
- 2固定キーを持つ辞書の定義辞書へのアクセスにおいて、特定の型安全なキーを使用することを保証するためにTypedDictを作成します。
- 3型チェッカーによるコードの検証mypyやpyrightコマンドを実行して、ソースディレクトリ内の型エラーをチェックします。
skill の SKILL.md から作成されています。すべてのユースケースは、その引用と照合されています。
python-typing-ops skillのインストール方法
各コマンドはskillフォルダをクライアントのskillsディレクトリにコピーします。読み込むには、クライアントを再起動するか新しいセッションを開始してください。プラグインにpython-typing-ops skillをインストールする
/plugin marketplace add 0xDarkMatter/claude-mods /plugin install claude-mods@claude-mods
Claude Codeにpython-typing-ops skillをインストールする
~/.claude/skills/python-typing-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-typing-ops ~/.claude/skills/python-typing-opsClaude Code (project)にpython-typing-ops skillをインストールする
.claude/skills/python-typing-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-typing-ops .claude/skills/python-typing-opsCodexにpython-typing-ops skillをインストールする
~/.agents/skills/python-typing-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-typing-ops ~/.agents/skills/python-typing-opsGemini CLIにpython-typing-ops skillをインストールする
~/.gemini/skills/python-typing-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-typing-ops ~/.gemini/skills/python-typing-opsClaude.aiにpython-typing-ops skillをインストールする
npx degit 0xDarkMatter/claude-mods/skills/python-typing-ops python-typing-ops && zip -r python-typing-ops.zip python-typing-ops # claude.ai → Customize → Skills → + → Create skill → Upload a skill → python-typing-ops.zip
自動チェック
実行日 2026年11月14日完全なレポート →自動チェックに合格しました。これはセキュリティ監査ではありません。エージェントに実行させる前にスクリプトを読んでください。 チェックの仕組み
- ソースリポジトリがリンクされており、アクセス可能0xdarkmatter/claude-mods/skills/python-typing-ops is public and reachablegithub.com/0xdarkmatter/claude-mods/tree/HEAD/skills/python- ↗合格
- オープンソースライセンス (OSI)MITspdx.org/licenses/MIT.html ↗合格
- 過去1年以内にコミットまたはリリースありLast commit 2026-11-07github.com/0xdarkmatter/claude-mods/commits ↗合格
- スクリプトにダウンロード実行や認証情報の窃取がない1 script read; no download-and-run, remote eval, base64 execution or credential upload合格
- SKILL.md に隠れた指示がないNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗合格
- 事前許可ツールが限定されているPre-approved: Read, Writegithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗合格
SKILL.md
GitHubで表示Python Typing Patterns
Modern type hints for safe, documented Python code.
Basic Annotations
# Variables
name: str = "Alice"
count: int = 42
items: list[str] = ["a", "b"]
mapping: dict[str, int] = {"key": 1}
# Function signatures
def greet(name: str, times: int = 1) -> str:
return f"Hello, {name}!" * times
# None handling
def find(id: int) -> str | None:
return db.get(id) # May return None
Collections
from collections.abc import Sequence, Mapping, Iterable
# Use collection ABCs for flexibility
def process(items: Sequence[str]) -> list[str]:
"""Accepts list, tuple, or any sequence."""
return [item.upper() for item in items]
def lookup(data: Mapping[str, int], key: str) -> int:
"""Accepts dict or any mapping."""
return data.get(key, 0)
# Nested types
Matrix = list[list[float]]
Config = dict[str, str | int | bool]
Optional and Union
# Modern syntax (3.10+)
def find(id: int) -> User | None:
pass
def parse(value: str | int | float) -> str:
pass
# With default None
def fetch(url: str, timeout: float | None = None) -> bytes:
pass
TypedDict
from typing import TypedDict, Required, NotRequired
class UserDict(TypedDict):
id: int
name: str
email: str | None
class ConfigDict(TypedDict, total=False): # All optional
debug: bool
log_level: str
class APIResponse(TypedDict):
data: Required[list[dict]]
error: NotRequired[str]
def process_user(user: UserDict) -> str:
return user["name"] # Type-safe key access
Callable
from collections.abc import Callable
# Function type
Handler = Callable[[str, int], bool]
def register(callback: Callable[[str], None]) -> None:
pass
# With keyword args (use Protocol instead)
from typing import Protocol
class Processor(Protocol):
def __call__(self, data: str, *, verbose: bool = False) -> int:
...
Generics
from typing import TypeVar
T = TypeVar("T")
def first(items: list[T]) -> T | None:
return items[0] if items else None
# Bounded TypeVar
from typing import SupportsFloat
N = TypeVar("N", bound=SupportsFloat)
def average(values: list[N]) -> float:
return sum(float(v) for v in values) / len(values)
Protocol (Structural Typing)
from typing import Protocol
class Readable(Protocol):
def read(self, n: int = -1) -> bytes:
...
def load(source: Readable) -> dict:
"""Accepts any object with read() method."""
data = source.read()
return json.loads(data)
# Works with file, BytesIO, custom classes
load(open("data.json", "rb"))
load(io.BytesIO(b"{}"))
Type Guards
from typing import TypeGuard
def is_string_list(val: list[object]) -> TypeGuard[list[str]]:
return all(isinstance(x, str) for x in val)
def process(items: list[object]) -> None:
if is_string_list(items):
# items is now list[str]
print(", ".join(items))
Literal and Final
from typing import Literal, Final
Mode = Literal["read", "write", "append"]
def open_file(path: str, mode: Mode) -> None:
pass
# Constants
MAX_SIZE: Final = 1024
API_VERSION: Final[str] = "v2"
Quick Reference
| Type | Use Case |
|---|---|
X | None |
Optional value |
list[T] |
Homogeneous list |
dict[K, V] |
Dictionary |
Callable[[Args], Ret] |
Function type |
TypeVar("T") |
Generic parameter |
Protocol |
Structural typing |
TypedDict |
Dict with fixed keys |
Literal["a", "b"] |
Specific values only |
Final |
Cannot be reassigned |
Type Checker Commands
# mypy (run inside the project env)
uv run mypy src/ --strict
# pyright
uv run pyright src/
# In pyproject.toml
[tool.mypy]
strict = true
python_version = "3.11"
Emerging: ty — Astral's Rust-based type checker (same toolchain as uv +
ruff), dramatically faster than mypy. Still in preview (pre-1.0), so mypy or
pyright remain the production default — but worth watching, and easy to try:
uvx ty check. Adopt for new projects once it stabilizes.
Additional Resources
./references/generics-advanced.md- TypeVar, ParamSpec, TypeVarTuple./references/protocols-patterns.md- Structural typing, runtime protocols./references/type-narrowing.md- Guards, isinstance, assert./references/mypy-config.md- mypy/pyright configuration./references/runtime-validation.md- Pydantic v2, typeguard, beartype./references/overloads.md- @overload decorator patterns
Scripts
./scripts/check-types.sh- Run type checkers with common options
Assets
./assets/pyproject-typing.toml- Recommended mypy/pyright config
See Also
This is a foundation skill with no prerequisites.
Related Skills:
python-pytest-ops- Type-safe fixtures and mocking
Build on this skill:
python-async-ops- Async type annotationspython-fastapi-ops- Pydantic models and validationpython-database-ops- SQLAlchemy type annotations
このスキルのファイル
9python-typing-ops skillに関する質問
Claude Codeにpython-typing-ops skillをインストールするには
npx degit 0xDarkMatter/claude-mods/skills/python-typing-ops ~/.claude/skills/python-typing-opsを実行してください。Claude Codeは~/.claude/skills(すべてのプロジェクト)または.claude/skills(単一プロジェクト)からskillsを読み込み、説明がタスクに一致する場合にskillを使用します。
python-typing-ops skillはどのクライアントで使用できますか
Agent Skills形式を読み込むすべてのクライアントで使用できます: Claude Code、Codex、Gemini CLI、claude.ai(ZIPとしてアップロード)。skill内のスクリプトは、クライアントがコード実行を許可した場合にのみ実行されます。
これらのパターンを使用するために必要なPythonのバージョンは何ですか?
これらのパターンはPython 3.10以降の構文(X | Y のUnion構文など)を使用しており、SelfやTypeVarTupleなどの特定のパターンにはPython 3.11以降が必要です。
プロジェクトで型チェッカーを実行するにはどうすればよいですか?
uvを使用してmypyやpyrightを実行できます。例:'uv run mypy src/ --strict' または 'uv run pyright src/'。
関数型におけるCallableとProtocolの違いは何ですか?
Callableは単純な関数型に使用されますが、キーワード引数を指定する必要がある場合はProtocolを使用します。