$npx -y skills add Jeffallan/claude-skills --skill python-proUse when building Python 3.11+ applications requiring type safety, async programming, or robust error handling. Generates type-annotated Python code, configures mypy in strict mode, writes pytest test suites with fixtures and mocking, and validates code with black and ruff. Invok
| 1 | # Python Pro |
| 2 | |
| 3 | Modern Python 3.11+ specialist focused on type-safe, async-first, production-ready code. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | - Writing type-safe Python with complete type coverage |
| 8 | - Implementing async/await patterns for I/O operations |
| 9 | - Setting up pytest test suites with fixtures and mocking |
| 10 | - Creating Pythonic code with comprehensions, generators, context managers |
| 11 | - Building packages with Poetry and proper project structure |
| 12 | - Performance optimization and profiling |
| 13 | |
| 14 | ## Core Workflow |
| 15 | |
| 16 | 1. **Analyze codebase** — Review structure, dependencies, type coverage, test suite |
| 17 | 2. **Design interfaces** — Define protocols, dataclasses, type aliases |
| 18 | 3. **Implement** — Write Pythonic code with full type hints and error handling |
| 19 | 4. **Test** — Create comprehensive pytest suite with >90% coverage |
| 20 | 5. **Validate** — Run `mypy --strict`, `black`, `ruff` |
| 21 | - If mypy fails: fix type errors reported and re-run before proceeding |
| 22 | - If tests fail: debug assertions, update fixtures, and iterate until green |
| 23 | - If ruff/black reports issues: apply auto-fixes, then re-validate |
| 24 | |
| 25 | ## Reference Guide |
| 26 | |
| 27 | Load detailed guidance based on context: |
| 28 | |
| 29 | | Topic | Reference | Load When | |
| 30 | |-------|-----------|-----------| |
| 31 | | Type System | `references/type-system.md` | Type hints, mypy, generics, Protocol | |
| 32 | | Async Patterns | `references/async-patterns.md` | async/await, asyncio, task groups | |
| 33 | | Standard Library | `references/standard-library.md` | pathlib, dataclasses, functools, itertools | |
| 34 | | Testing | `references/testing.md` | pytest, fixtures, mocking, parametrize | |
| 35 | | Packaging | `references/packaging.md` | poetry, pip, pyproject.toml, distribution | |
| 36 | |
| 37 | ## Constraints |
| 38 | |
| 39 | ### MUST DO |
| 40 | - Type hints for all function signatures and class attributes |
| 41 | - PEP 8 compliance with black formatting |
| 42 | - Comprehensive docstrings (Google style) |
| 43 | - Test coverage exceeding 90% with pytest |
| 44 | - Use `X | None` instead of `Optional[X]` (Python 3.10+) |
| 45 | - Async/await for I/O-bound operations |
| 46 | - Dataclasses over manual __init__ methods |
| 47 | - Context managers for resource handling |
| 48 | |
| 49 | ### MUST NOT DO |
| 50 | - Skip type annotations on public APIs |
| 51 | - Use mutable default arguments |
| 52 | - Mix sync and async code improperly |
| 53 | - Ignore mypy errors in strict mode |
| 54 | - Use bare except clauses |
| 55 | - Hardcode secrets or configuration |
| 56 | - Use deprecated stdlib modules (use pathlib not os.path) |
| 57 | |
| 58 | ## Code Examples |
| 59 | |
| 60 | ### Type-annotated function with error handling |
| 61 | ```python |
| 62 | from pathlib import Path |
| 63 | |
| 64 | def read_config(path: Path) -> dict[str, str]: |
| 65 | """Read configuration from a file. |
| 66 | |
| 67 | Args: |
| 68 | path: Path to the configuration file. |
| 69 | |
| 70 | Returns: |
| 71 | Parsed key-value configuration entries. |
| 72 | |
| 73 | Raises: |
| 74 | FileNotFoundError: If the config file does not exist. |
| 75 | ValueError: If a line cannot be parsed. |
| 76 | """ |
| 77 | config: dict[str, str] = {} |
| 78 | with path.open() as f: |
| 79 | for line in f: |
| 80 | key, _, value = line.partition("=") |
| 81 | if not key.strip(): |
| 82 | raise ValueError(f"Invalid config line: {line!r}") |
| 83 | config[key.strip()] = value.strip() |
| 84 | return config |
| 85 | ``` |
| 86 | |
| 87 | ### Dataclass with validation |
| 88 | ```python |
| 89 | from dataclasses import dataclass, field |
| 90 | |
| 91 | @dataclass |
| 92 | class AppConfig: |
| 93 | host: str |
| 94 | port: int |
| 95 | debug: bool = False |
| 96 | allowed_origins: list[str] = field(default_factory=list) |
| 97 | |
| 98 | def __post_init__(self) -> None: |
| 99 | if not (1 <= self.port <= 65535): |
| 100 | raise ValueError(f"Invalid port: {self.port}") |
| 101 | ``` |
| 102 | |
| 103 | ### Async pattern |
| 104 | ```python |
| 105 | import asyncio |
| 106 | import httpx |
| 107 | |
| 108 | async def fetch_all(urls: list[str]) -> list[bytes]: |
| 109 | """Fetch multiple URLs concurrently.""" |
| 110 | async with httpx.AsyncClient() as client: |
| 111 | tasks = [client.get(url) for url in urls] |
| 112 | responses = await asyncio.gather(*tasks) |
| 113 | return [r.content for r in responses] |
| 114 | ``` |
| 115 | |
| 116 | ### pytest fixture and parametrize |
| 117 | ```python |
| 118 | import pytest |
| 119 | from pathlib import Path |
| 120 | |
| 121 | @pytest.fixture |
| 122 | def config_file(tmp_path: Path) -> Path: |
| 123 | cfg = tmp_path / "config.txt" |
| 124 | cfg.write_text("host=localhost\nport=8080\n") |
| 125 | return cfg |
| 126 | |
| 127 | @pytest.mark.parametrize("port,valid", [(8080, True), (0, False), (99999, False)]) |
| 128 | def test_app_config_port_validation(port: int, valid: bool) -> None: |
| 129 | if valid: |
| 130 | AppConfig(host="localh |