{"id":"python-pro","name":"python-pro","summary":"型安全性、非同期プログラミング、または堅牢なエラー処理を必要とするPython 3.11+アプリケーションを構築する際に利用します。","body":"# Python Pro\n\nModern Python 3.11+ specialist focused on type-safe, async-first, production-ready code.\n\n## When to Use This Skill\n\n- Writing type-safe Python with complete type coverage\n- Implementing async/await patterns for I/O operations\n- Setting up pytest test suites with fixtures and mocking\n- Creating Pythonic code with comprehensions, generators, context managers\n- Building packages with Poetry and proper project structure\n- Performance optimization and profiling\n\n## Core Workflow\n\n1. **Analyze codebase** — Review structure, dependencies, type coverage, test suite\n2. **Design interfaces** — Define protocols, dataclasses, type aliases\n3. **Implement** — Write Pythonic code with full type hints and error handling\n4. **Test** — Create comprehensive pytest suite with >90% coverage\n5. **Validate** — Run `mypy --strict`, `black`, `ruff`\n   - If mypy fails: fix type errors reported and re-run before proceeding\n   - If tests fail: debug assertions, update fixtures, and iterate until green\n   - If ruff/black reports issues: apply auto-fixes, then re-validate\n\n## Reference Guide\n\nLoad detailed guidance based on context:\n\n| Topic | Reference | Load When |\n|-------|-----------|-----------|\n| Type System | `references/type-system.md` | Type hints, mypy, generics, Protocol |\n| Async Patterns | `references/async-patterns.md` | async/await, asyncio, task groups |\n| Standard Library | `references/standard-library.md` | pathlib, dataclasses, functools, itertools |\n| Testing | `references/testing.md` | pytest, fixtures, mocking, parametrize |\n| Packaging | `references/packaging.md` | poetry, pip, pyproject.toml, distribution |\n\n## Constraints\n\n### MUST DO\n- Type hints for all function signatures and class attributes\n- PEP 8 compliance with black formatting\n- Comprehensive docstrings (Google style)\n- Test coverage exceeding 90% with pytest\n- Use `X | None` instead of `Optional[X]` (Python 3.10+)\n- Async/await for I/O-bound operations\n- Dataclasses over manual __init__ methods\n- Context managers for resource handling\n\n### MUST NOT DO\n- Skip type annotations on public APIs\n- Use mutable default arguments\n- Mix sync and async code improperly\n- Ignore mypy errors in strict mode\n- Use bare except clauses\n- Hardcode secrets or configuration\n- Use deprecated stdlib modules (use pathlib not os.path)\n\n## Code Examples\n\n### Type-annotated function with error handling\n```python\nfrom pathlib import Path\n\ndef read_config(path: Path) -> dict[str, str]:\n    \"\"\"Read configuration from a file.\n\n    Args:\n        path: Path to the configuration file.\n\n    Returns:\n        Parsed key-value configuration entries.\n\n    Raises:\n        FileNotFoundError: If the config file does not exist.\n        ValueError: If a line cannot be parsed.\n    \"\"\"\n    config: dict[str, str] = {}\n    with path.open() as f:\n        for line in f:\n            key, _, value = line.partition(\"=\")\n            if not key.strip():\n                raise ValueError(f\"Invalid config line: {line!r}\")\n            config[key.strip()] = value.strip()\n    return config\n```\n\n### Dataclass with validation\n```python\nfrom dataclasses import dataclass, field\n\n@dataclass\nclass AppConfig:\n    host: str\n    port: int\n    debug: bool = False\n    allowed_origins: list[str] = field(default_factory=list)\n\n    def __post_init__(self) -> None:\n        if not (1 <= self.port <= 65535):\n            raise ValueError(f\"Invalid port: {self.port}\")\n```\n\n### Async pattern\n```python\nimport asyncio\nimport httpx\n\nasync def fetch_all(urls: list[str]) -> list[bytes]:\n    \"\"\"Fetch multiple URLs concurrently.\"\"\"\n    async with httpx.AsyncClient() as client:\n        tasks = [client.get(url) for url in urls]\n        responses = await asyncio.gather(*tasks)\n        return [r.content for r in responses]\n```\n\n### pytest fixture and parametrize\n```python\nimport pytest\nfrom pathlib import Path\n\n@pytest.fixture\ndef config_file(tmp_path: Path) -> Path:\n    cfg = tmp_path / \"config.txt\"\n    cfg.write_text(\"host=localhost\\nport=8080\\n\")\n    return cfg\n\n@pytest.mark.parametrize(\"port,valid\", [(8080, True), (0, False), (99999, False)])\ndef test_app_config_port_validation(port: int, valid: bool) -> None:\n    if valid:\n        AppConfig(host=\"localhost\", port=port)\n    else:\n        with pytest.raises(ValueError):\n            AppConfig(host=\"localhost\", port=port)\n```\n\n### mypy strict configuration (pyproject.toml)\n```toml\n[tool.mypy]\npython_version = \"3.11\"\nstrict = true\nwarn_return_any = true\nwarn_unused_configs = true\ndisallow_untyped_defs = true\n```\n\nClean `mypy --strict` output looks like:\n```\nSuccess: no issues found in 12 source files\n```\nAny reported error (e.g., `error: Function is missing a return type annotation`) must be resolved before the implementation is considered complete.\n\n## Output Templates\n\nWhen implementing Python features, provide:\n1. Module file with complete type hints\n2. Test file with pytest fixtures\n3. Type checking confirmation (mypy --strict passes)\n4. Brief explanation of Pythonic patterns used\n\n## Knowledge Reference\n\nPython 3.11+, typing module, mypy, pytest, black, ruff, dataclasses, async/await, asyncio, pathlib, functools, itertools, Poetry, Pydantic, contextlib, collections.abc, Protocol\n\n[Documentation](https://jeffallan.github.io/claude-skills/skills/language/python-pro/)","author":"@Jeffallan","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/Jeffallan/claude-skills/tree/main/skills/python-pro","license":"MIT","category":"writing","lang":"en","tokens":1244,"stars":0,"calls30d":0,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"references/async-patterns.md","size":9333,"sha256":"b7986eb185a4858de3edcb27f537a38d351d3017fdbcac3ba2d905d30ba1cb64"},{"path":"references/packaging.md","size":9652,"sha256":"483d0a257907d2e17ce1cf2e3e7b8b2af88f9eb17fa3a9c4bcc04aa60e930ae3"},{"path":"references/standard-library.md","size":9063,"sha256":"d2997c8f9a491561947c95a182e09b2d584d828d26cb04eb42a194fa4393c6ce"},{"path":"references/testing.md","size":9920,"sha256":"81c8bc148eaf7d32e51171c997016c7deda140b71d6253b15b63b10f038f3c28"},{"path":"references/type-system.md","size":6638,"sha256":"62c4474c4ed29a18fd64002a356cba0239785f68c8530109c74c5bb3162b021b"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":["api.example.com","jeffallan.github.io","myproject.readthedocs.io","test.pypi.org"]}}