[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M72XWMZF7RE0ZCN8VSAY97ES":3,"skill-same:01M72XWMZF7RE0ZCN8VSAY97ES":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":28,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M72XWMZF7RE0ZCN8VSAY97ES","python-type-safety",null,"Python type safety with type hints, generics, protocols, and strict type checking. Use when adding type annotations, implementing generic classes, defining structural interfaces, or configuring mypy\u002Fpyright.","steph-frtech\u002Fclaude-code-up","steph-frtech","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F198466323?v=4","01M72XD213FVQA2QXRGTJFKHE1","01M72XD227AANJ993SQTNZB1CK",1,"MIT","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fmarketplaces\u002Fwshobson\u002Fplugins\u002Fpython-development\u002Fskills\u002Fpython-type-safety\u002FSKILL.md",[],[],"2026-11-10 22:39:42",false,"---\nname: python-type-safety\ndescription: Python type safety with type hints, generics, protocols, and strict type checking. Use when adding type annotations, implementing generic classes, defining structural interfaces, or configuring mypy\u002Fpyright.\n---\n\n# Python Type Safety\n\nLeverage Python's type system to catch errors at static analysis time. Type annotations serve as enforced documentation that tooling validates automatically.\n\n## When to Use This Skill\n\n- Adding type hints to existing code\n- Creating generic, reusable classes\n- Defining structural interfaces with protocols\n- Configuring mypy or pyright for strict checking\n- Understanding type narrowing and guards\n- Building type-safe APIs and libraries\n\n## Core Concepts\n\n### 1. Type Annotations\n\nDeclare expected types for function parameters, return values, and variables.\n\n### 2. Generics\n\nWrite reusable code that preserves type information across different types.\n\n### 3. Protocols\n\nDefine structural interfaces without inheritance (duck typing with type safety).\n\n### 4. Type Narrowing\n\nUse guards and conditionals to narrow types within code blocks.\n\n## Quick Start\n\n```python\ndef get_user(user_id: str) -> User | None:\n    \"\"\"Return type makes 'might not exist' explicit.\"\"\"\n    ...\n\n# Type checker enforces handling None case\nuser = get_user(\"123\")\nif user is None:\n    raise UserNotFoundError(\"123\")\nprint(user.name)  # Type checker knows user is User here\n```\n\n## Fundamental Patterns\n\n### Pattern 1: Annotate All Public Signatures\n\nEvery public function, method, and class should have type annotations.\n\n```python\ndef get_user(user_id: str) -> User:\n    \"\"\"Retrieve user by ID.\"\"\"\n    ...\n\ndef process_batch(\n    items: list[Item],\n    max_workers: int = 4,\n) -> BatchResult[ProcessedItem]:\n    \"\"\"Process items concurrently.\"\"\"\n    ...\n\nclass UserRepository:\n    def __init__(self, db: Database) -> None:\n        self._db = db\n\n    async def find_by_id(self, user_id: str) -> User | None:\n        \"\"\"Return User if found, None otherwise.\"\"\"\n        ...\n\n    async def find_by_email(self, email: str) -> User | None:\n        ...\n\n    async def save(self, user: User) -> User:\n        \"\"\"Save and return user with generated ID.\"\"\"\n        ...\n```\n\nUse `mypy --strict` or `pyright` in CI to catch type errors early. For existing projects, enable strict mode incrementally using per-module overrides.\n\n### Pattern 2: Use Modern Union Syntax\n\nPython 3.10+ provides cleaner union syntax.\n\n```python\n# Preferred (3.10+)\ndef find_user(user_id: str) -> User | None:\n    ...\n\ndef parse_value(v: str) -> int | float | str:\n    ...\n\n# Older style (still valid, needed for 3.9)\nfrom typing import Optional, Union\n\ndef find_user(user_id: str) -> Optional[User]:\n    ...\n```\n\n### Pattern 3: Type Narrowing with Guards\n\nUse conditionals to narrow types for the type checker.\n\n```python\ndef process_user(user_id: str) -> UserData:\n    user = find_user(user_id)\n\n    if user is None:\n        raise UserNotFoundError(f\"User {user_id} not found\")\n\n    # Type checker knows user is User here, not User | None\n    return UserData(\n        name=user.name,\n        email=user.email,\n    )\n\ndef process_items(items: list[Item | None]) -> list[ProcessedItem]:\n    # Filter and narrow types\n    valid_items = [item for item in items if item is not None]\n    # valid_items is now list[Item]\n    return [process(item) for item in valid_items]\n```\n\n### Pattern 4: Generic Classes\n\nCreate type-safe reusable containers.\n\n```python\nfrom typing import TypeVar, Generic\n\nT = TypeVar(\"T\")\nE = TypeVar(\"E\", bound=Exception)\n\nclass Result(Generic[T, E]):\n    \"\"\"Represents either a success value or an error.\"\"\"\n\n    def __init__(\n        self,\n        value: T | None = None,\n        error: E | None = None,\n    ) -> None:\n        if (value is None) == (error is None):\n            raise ValueError(\"Exactly one of value or error must be set\")\n        self._value = value\n        self._error = error\n\n    @property\n    def is_success(self) -> bool:\n        return self._error is None\n\n    @property\n    def is_failure(self) -> bool:\n        return self._error is not None\n\n    def unwrap(self) -> T:\n        \"\"\"Get value or raise the error.\"\"\"\n        if self._error is not None:\n            raise self._error\n        return self._value  # type: ignore[return-value]\n\n    def unwrap_or(self, default: T) -> T:\n        \"\"\"Get value or return default.\"\"\"\n        if self._error is not None:\n            return default\n        return self._value  # type: ignore[return-value]\n\n# Usage preserves types\ndef parse_config(path: str) -> Result[Config, ConfigError]:\n    try:\n        return Result(value=Config.from_file(path))\n    except ConfigError as e:\n        return Result(error=e)\n\nresult = parse_config(\"config.yaml\")\nif result.is_success:\n    config = result.unwrap()  # Type: Config\n```\n\n## Advanced Patterns\n\n### Pattern 5: Generic Repository\n\nCreate type-safe data access patterns.\n\n```python\nfrom typing import TypeVar, Generic\nfrom abc import ABC, abstractmethod\n\nT = TypeVar(\"T\")\nID = TypeVar(\"ID\")\n\nclass Repository(ABC, Generic[T, ID]):\n    \"\"\"Generic repository interface.\"\"\"\n\n    @abstractmethod\n    async def get(self, id: ID) -> T | None:\n        \"\"\"Get entity by ID.\"\"\"\n        ...\n\n    @abstractmethod\n    async def save(self, entity: T) -> T:\n        \"\"\"Save and return entity.\"\"\"\n        ...\n\n    @abstractmethod\n    async def delete(self, id: ID) -> bool:\n        \"\"\"Delete entity, return True if existed.\"\"\"\n        ...\n\nclass UserRepository(Repository[User, str]):\n    \"\"\"Concrete repository for Users with string IDs.\"\"\"\n\n    async def get(self, id: str) -> User | None:\n        row = await self._db.fetchrow(\n            \"SELECT * FROM users WHERE id = $1\", id\n        )\n        return User(**row) if row else None\n\n    async def save(self, entity: User) -> User:\n        ...\n\n    async def delete(self, id: str) -> bool:\n        ...\n```\n\n### Pattern 6: TypeVar with Bounds\n\nRestrict generic parameters to specific types.\n\n```python\nfrom typing import TypeVar\nfrom pydantic import BaseModel\n\nModelT = TypeVar(\"ModelT\", bound=BaseModel)\n\ndef validate_and_create(model_cls: type[ModelT], data: dict) -> ModelT:\n    \"\"\"Create a validated Pydantic model from dict.\"\"\"\n    return model_cls.model_validate(data)\n\n# Works with any BaseModel subclass\nclass User(BaseModel):\n    name: str\n    email: str\n\nuser = validate_and_create(User, {\"name\": \"Alice\", \"email\": \"a@b.com\"})\n# user is typed as User\n\n# Type error: str is not a BaseModel subclass\nresult = validate_and_create(str, {\"name\": \"Alice\"})  # Error!\n```\n\n### Pattern 7: Protocols for Structural Typing\n\nDefine interfaces without requiring inheritance.\n\n```python\nfrom typing import Protocol, runtime_checkable\n\n@runtime_checkable\nclass Serializable(Protocol):\n    \"\"\"Any class that can be serialized to\u002Ffrom dict.\"\"\"\n\n    def to_dict(self) -> dict:\n        ...\n\n    @classmethod\n    def from_dict(cls, data: dict) -> \"Serializable\":\n        ...\n\n# User satisfies Serializable without inheriting from it\nclass User:\n    def __init__(self, id: str, name: str) -> None:\n        self.id = id\n        self.name = name\n\n    def to_dict(self) -> dict:\n        return {\"id\": self.id, \"name\": self.name}\n\n    @classmethod\n    def from_dict(cls, data: dict) -> \"User\":\n        return cls(id=data[\"id\"], name=data[\"name\"])\n\ndef serialize(obj: Serializable) -> str:\n    \"\"\"Works with any Serializable object.\"\"\"\n    return json.dumps(obj.to_dict())\n\n# Works - User matches the protocol\nserialize(User(\"1\", \"Alice\"))\n\n# Runtime checking with @runtime_checkable\nisinstance(User(\"1\", \"Alice\"), Serializable)  # True\n```\n\n### Pattern 8: Common Protocol Patterns\n\nDefine reusable structural interfaces.\n\n```python\nfrom typing import Protocol\n\nclass Closeable(Protocol):\n    \"\"\"Resource that can be closed.\"\"\"\n    def close(self) -> None: ...\n\nclass AsyncCloseable(Protocol):\n    \"\"\"Async resource that can be closed.\"\"\"\n    async def close(self) -> None: ...\n\nclass Readable(Protocol):\n    \"\"\"Object that can be read from.\"\"\"\n    def read(self, n: int = -1) -> bytes: ...\n\nclass HasId(Protocol):\n    \"\"\"Object with an ID property.\"\"\"\n    @property\n    def id(self) -> str: ...\n\nclass Comparable(Protocol):\n    \"\"\"Object that supports comparison.\"\"\"\n    def __lt__(self, other: \"Comparable\") -> bool: ...\n    def __le__(self, other: \"Comparable\") -> bool: ...\n```\n\n### Pattern 9: Type Aliases\n\nCreate meaningful type names.\n\n**Note:** The `type Alias = ...` statement syntax (PEP 695) was introduced in **Python 3.12**, not 3.10. For projects targeting earlier versions (including 3.10\u002F3.11), use the `TypeAlias` annotation (PEP 613, available since Python 3.10).\n\n```python\n# Python 3.12+ type statement (PEP 695)\ntype UserId = str\ntype UserDict = dict[str, Any]\n\n# Python 3.12+ type statement with generics (PEP 695)\ntype Handler[T] = Callable[[Request], T]\ntype AsyncHandler[T] = Callable[[Request], Awaitable[T]]\n```\n\n```python\n# Python 3.10-3.11 style (needed for broader compatibility)\nfrom typing import TypeAlias\nfrom collections.abc import Callable, Awaitable\n\nUserId: TypeAlias = str\nHandler: TypeAlias = Callable[[Request], Response]\n```\n\n```python\n# Usage\ndef register_handler(path: str, handler: Handler[Response]) -> None:\n    ...\n```\n\n### Pattern 10: Callable Types\n\nType function parameters and callbacks.\n\n```python\nfrom collections.abc import Callable, Awaitable\n\n# Sync callback\nProgressCallback = Callable[[int, int], None]  # (current, total)\n\n# Async callback\nAsyncHandler = Callable[[Request], Awaitable[Response]]\n\n# With named parameters (using Protocol)\nclass OnProgress(Protocol):\n    def __call__(\n        self,\n        current: int,\n        total: int,\n        *,\n        message: str = \"\",\n    ) -> None: ...\n\ndef process_items(\n    items: list[Item],\n    on_progress: ProgressCallback | None = None,\n) -> list[Result]:\n    for i, item in enumerate(items):\n        if on_progress:\n            on_progress(i, len(items))\n        ...\n```\n\n## Configuration\n\n### Strict Mode Checklist\n\nFor `mypy --strict` compliance:\n\n```toml\n# pyproject.toml\n[tool.mypy]\npython_version = \"3.12\"\nstrict = true\nwarn_return_any = true\nwarn_unused_ignores = true\ndisallow_untyped_defs = true\ndisallow_incomplete_defs = true\nno_implicit_optional = true\n```\n\nIncremental adoption goals:\n- All function parameters annotated\n- All return types annotated\n- Class attributes annotated\n- Minimize `Any` usage (acceptable for truly dynamic data)\n- Generic collections use type parameters (`list[str]` not `list`)\n\nFor existing codebases, enable strict mode per-module using `# mypy: strict` or configure per-module overrides in `pyproject.toml`.\n\n## Best Practices Summary\n\n1. **Annotate all public APIs** - Functions, methods, class attributes\n2. **Use `T | None`** - Modern union syntax over `Optional[T]`\n3. **Run strict type checking** - `mypy --strict` in CI\n4. **Use generics** - Preserve type info in reusable code\n5. **Define protocols** - Structural typing for interfaces\n6. **Narrow types** - Use guards to help the type checker\n7. **Bound type vars** - Restrict generics to meaningful types\n8. **Create type aliases** - Meaningful names for complex types\n9. **Minimize `Any`** - Use specific types or generics. `Any` is acceptable for truly dynamic data or when interfacing with untyped third-party code\n10. **Document with types** - Types are enforceable documentation\n","# Python Type Safety\n\nLeverage Python's type system to catch errors at static analysis time. Type annotations serve as enforced documentation that tooling validates automatically.\n\n## When to Use This Skill\n\n- Adding type hints to existing code\n- Creating generic, reusable classes\n- Defining structural interfaces with protocols\n- Configuring mypy or pyright for strict checking\n- Understanding type narrowing and guards\n- Building type-safe APIs and libraries\n\n## Core Concepts\n\n### 1. Type Annotations\n\nDeclare expected types for function parameters, return values, and variables.\n\n### 2. Generics\n\nWrite reusable code that preserves type information across different types.\n\n### 3. Protocols\n\nDefine structural interfaces without inheritance (duck typing with type safety).\n\n### 4. Type Narrowing\n\nUse guards and conditionals to narrow types within code blocks.\n\n## Quick Start\n\n```python\ndef get_user(user_id: str) -> User | None:\n    \"\"\"Return type makes 'might not exist' explicit.\"\"\"\n    ...\n\n# Type checker enforces handling None case\nuser = get_user(\"123\")\nif user is None:\n    raise UserNotFoundError(\"123\")\nprint(user.name)  # Type checker knows user is User here\n```\n\n## Fundamental Patterns\n\n### Pattern 1: Annotate All Public Signatures\n\nEvery public function, method, and class should have type annotations.\n\n```python\ndef get_user(user_id: str) -> User:\n    \"\"\"Retrieve user by ID.\"\"\"\n    ...\n\ndef process_batch(\n    items: list[Item],\n    max_workers: int = 4,\n) -> BatchResult[ProcessedItem]:\n    \"\"\"Process items concurrently.\"\"\"\n    ...\n\nclass UserRepository:\n    def __init__(self, db: Database) -> None:\n        self._db = db\n\n    async def find_by_id(self, user_id: str) -> User | None:\n        \"\"\"Return User if found, None otherwise.\"\"\"\n        ...\n\n    async def find_by_email(self, email: str) -> User | None:\n        ...\n\n    async def save(self, user: User) -> User:\n        \"\"\"Save and return user with generated ID.\"\"\"\n        ...\n```\n\nUse `mypy --strict` or `pyright` in CI to catch type errors early. For existing projects, enable strict mode incrementally using per-module overrides.\n\n### Pattern 2: Use Modern Union Syntax\n\nPython 3.10+ provides cleaner union syntax.\n\n```python\n# Preferred (3.10+)\ndef find_user(user_id: str) -> User | None:\n    ...\n\ndef parse_value(v: str) -> int | float | str:\n    ...\n\n# Older style (still valid, needed for 3.9)\nfrom typing import Optional, Union\n\ndef find_user(user_id: str) -> Optional[User]:\n    ...\n```\n\n### Pattern 3: Type Narrowing with Guards\n\nUse conditionals to narrow types for the type checker.\n\n```python\ndef process_user(user_id: str) -> UserData:\n    user = find_user(user_id)\n\n    if user is None:\n        raise UserNotFoundError(f\"User {user_id} not found\")\n\n    # Type checker knows user is User here, not User | None\n    return UserData(\n        name=user.name,\n        email=user.email,\n    )\n\ndef process_items(items: list[Item | None]) -> list[ProcessedItem]:\n    # Filter and narrow types\n    valid_items = [item for item in items if item is not None]\n    # valid_items is now list[Item]\n    return [process(item) for item in valid_items]\n```\n\n### Pattern 4: Generic Classes\n\nCreate type-safe reusable containers.\n\n```python\nfrom typing import TypeVar, Generic\n\nT = TypeVar(\"T\")\nE = TypeVar(\"E\", bound=Exception)\n\nclass Result(Generic[T, E]):\n    \"\"\"Represents either a success value or an error.\"\"\"\n\n    def __init__(\n        self,\n        value: T | None = None,\n        error: E | None = None,\n    ) -> None:\n        if (value is None) == (error is None):\n            raise ValueError(\"Exactly one of value or error must be set\")\n        self._value = value\n        self._error = error\n\n    @property\n    def is_success(self) -> bool:\n        return self._error is None\n\n    @property\n    def is_failure(self) -> bool:\n        return self._error is not None\n\n    def unwrap(self) -> T:\n        \"\"\"Get value or raise the error.\"\"\"\n        if self._error is not None:\n            raise self._error\n        return self._value  # type: ignore[return-value]\n\n    def unwrap_or(self, default: T) -> T:\n        \"\"\"Get value or return default.\"\"\"\n        if self._error is not None:\n            return default\n        return self._value  # type: ignore[return-value]\n\n# Usage preserves types\ndef parse_config(path: str) -> Result[Config, ConfigError]:\n    try:\n        return Result(value=Config.from_file(path))\n    except ConfigError as e:\n        return Result(error=e)\n\nresult = parse_config(\"config.yaml\")\nif result.is_success:\n    config = result.unwrap()  # Type: Config\n```\n\n## Advanced Patterns\n\n### Pattern 5: Generic Repository\n\nCreate type-safe data access patterns.\n\n```python\nfrom typing import TypeVar, Generic\nfrom abc import ABC, abstractmethod\n\nT = TypeVar(\"T\")\nID = TypeVar(\"ID\")\n\nclass Repository(ABC, Generic[T, ID]):\n    \"\"\"Generic repository interface.\"\"\"\n\n    @abstractmethod\n    async def get(self, id: ID) -> T | None:\n        \"\"\"Get entity by ID.\"\"\"\n        ...\n\n    @abstractmethod\n    async def save(self, entity: T) -> T:\n        \"\"\"Save and return entity.\"\"\"\n        ...\n\n    @abstractmethod\n    async def delete(self, id: ID) -> bool:\n        \"\"\"Delete entity, return True if existed.\"\"\"\n        ...\n\nclass UserRepository(Repository[User, str]):\n    \"\"\"Concrete repository for Users with string IDs.\"\"\"\n\n    async def get(self, id: str) -> User | None:\n        row = await self._db.fetchrow(\n            \"SELECT * FROM users WHERE id = $1\", id\n        )\n        return User(**row) if row else None\n\n    async def save(self, entity: User) -> User:\n        ...\n\n    async def delete(self, id: str) -> bool:\n        ...\n```\n\n### Pattern 6: TypeVar with Bounds\n\nRestrict generic parameters to specific types.\n\n```python\nfrom typing import TypeVar\nfrom pydantic import BaseModel\n\nModelT = TypeVar(\"ModelT\", bound=BaseModel)\n\ndef validate_and_create(model_cls: type[ModelT], data: dict) -> ModelT:\n    \"\"\"Create a validated Pydantic model from dict.\"\"\"\n    return model_cls.model_validate(data)\n\n# Works with any BaseModel subclass\nclass User(BaseModel):\n    name: str\n    email: str\n\nuser = validate_and_create(User, {\"name\": \"Alice\", \"email\": \"a@b.com\"})\n# user is typed as User\n\n# Type error: str is not a BaseModel subclass\nresult = validate_and_create(str, {\"name\": \"Alice\"})  # Error!\n```\n\n### Pattern 7: Protocols for Structural Typing\n\nDefine interfaces without requiring inheritance.\n\n```python\nfrom typing import Protocol, runtime_checkable\n\n@runtime_checkable\nclass Serializable(Protocol):\n    \"\"\"Any class that can be serialized to\u002Ffrom dict.\"\"\"\n\n    def to_dict(self) -> dict:\n        ...\n\n    @classmethod\n    def from_dict(cls, data: dict) -> \"Serializable\":\n        ...\n\n# User satisfies Serializable without inheriting from it\nclass User:\n    def __init__(self, id: str, name: str) -> None:\n        self.id = id\n        self.name = name\n\n    def to_dict(self) -> dict:\n        return {\"id\": self.id, \"name\": self.name}\n\n    @classmethod\n    def from_dict(cls, data: dict) -> \"User\":\n        return cls(id=data[\"id\"], name=data[\"name\"])\n\ndef serialize(obj: Serializable) -> str:\n    \"\"\"Works with any Serializable object.\"\"\"\n    return json.dumps(obj.to_dict())\n\n# Works - User matches the protocol\nserialize(User(\"1\", \"Alice\"))\n\n# Runtime checking with @runtime_checkable\nisinstance(User(\"1\", \"Alice\"), Serializable)  # True\n```\n\n### Pattern 8: Common Protocol Patterns\n\nDefine reusable structural interfaces.\n\n```python\nfrom typing import Protocol\n\nclass Closeable(Protocol):\n    \"\"\"Resource that can be closed.\"\"\"\n    def close(self) -> None: ...\n\nclass AsyncCloseable(Protocol):\n    \"\"\"Async resource that can be closed.\"\"\"\n    async def close(self) -> None: ...\n\nclass Readable(Protocol):\n    \"\"\"Object that can be read from.\"\"\"\n    def read(self, n: int = -1) -> bytes: ...\n\nclass HasId(Protocol):\n    \"\"\"Object with an ID property.\"\"\"\n    @property\n    def id(self) -> str: ...\n\nclass Comparable(Protocol):\n    \"\"\"Object that supports comparison.\"\"\"\n    def __lt__(self, other: \"Comparable\") -> bool: ...\n    def __le__(self, other: \"Comparable\") -> bool: ...\n```\n\n### Pattern 9: Type Aliases\n\nCreate meaningful type names.\n\n**Note:** The `type Alias = ...` statement syntax (PEP 695) was introduced in **Python 3.12**, not 3.10. For projects targeting earlier versions (including 3.10\u002F3.11), use the `TypeAlias` annotation (PEP 613, available since Python 3.10).\n\n```python\n# Python 3.12+ type statement (PEP 695)\ntype UserId = str\ntype UserDict = dict[str, Any]\n\n# Python 3.12+ type statement with generics (PEP 695)\ntype Handler[T] = Callable[[Request], T]\ntype AsyncHandler[T] = Callable[[Request], Awaitable[T]]\n```\n\n```python\n# Python 3.10-3.11 style (needed for broader compatibility)\nfrom typing import TypeAlias\nfrom collections.abc import Callable, Awaitable\n\nUserId: TypeAlias = str\nHandler: TypeAlias = Callable[[Request], Response]\n```\n\n```python\n# Usage\ndef register_handler(path: str, handler: Handler[Response]) -> None:\n    ...\n```\n\n### Pattern 10: Callable Types\n\nType function parameters and callbacks.\n\n```python\nfrom collections.abc import Callable, Awaitable\n\n# Sync callback\nProgressCallback = Callable[[int, int], None]  # (current, total)\n\n# Async callback\nAsyncHandler = Callable[[Request], Awaitable[Response]]\n\n# With named parameters (using Protocol)\nclass OnProgress(Protocol):\n    def __call__(\n        self,\n        current: int,\n        total: int,\n        *,\n        message: str = \"\",\n    ) -> None: ...\n\ndef process_items(\n    items: list[Item],\n    on_progress: ProgressCallback | None = None,\n) -> list[Result]:\n    for i, item in enumerate(items):\n        if on_progress:\n            on_progress(i, len(items))\n        ...\n```\n\n## Configuration\n\n### Strict Mode Checklist\n\nFor `mypy --strict` compliance:\n\n```toml\n# pyproject.toml\n[tool.mypy]\npython_version = \"3.12\"\nstrict = true\nwarn_return_any = true\nwarn_unused_ignores = true\ndisallow_untyped_defs = true\ndisallow_incomplete_defs = true\nno_implicit_optional = true\n```\n\nIncremental adoption goals:\n- All function parameters annotated\n- All return types annotated\n- Class attributes annotated\n- Minimize `Any` usage (acceptable for truly dynamic data)\n- Generic collections use type parameters (`list[str]` not `list`)\n\nFor existing codebases, enable strict mode per-module using `# mypy: strict` or configure per-module overrides in `pyproject.toml`.\n\n## Best Practices Summary\n\n1. **Annotate all public APIs** - Functions, methods, class attributes\n2. **Use `T | None`** - Modern union syntax over `Optional[T]`\n3. **Run strict type checking** - `mypy --strict` in CI\n4. **Use generics** - Preserve type info in reusable code\n5. **Define protocols** - Structural typing for interfaces\n6. **Narrow types** - Use guards to help the type checker\n7. **Bound type vars** - Restrict generics to meaningful types\n8. **Create type aliases** - Meaningful names for complex types\n9. **Minimize `Any`** - Use specific types or generics. `Any` is acceptable for truly dynamic data or when interfacing with untyped third-party code\n10. **Document with types** - Types are enforceable documentation\n",{"name":5,"description":7},"main","900bb95bbe72cdb94af6f5a620aa5081264b7b6d",".claude\u002Fmarketplaces\u002Fwshobson\u002Fplugins\u002Fpython-development\u002Fskills\u002Fpython-type-safety",0,"https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up#readme","https:\u002F\u002Fgithub.com\u002Fsteph-frtech","2026-05-16 00:03:30",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add steph-frtech\u002Fclaude-code-up --skill python-type-safety",{"tool":37,"command":38},"bunx","bunx skills add steph-frtech\u002Fclaude-code-up --skill python-type-safety",{"tool":40,"command":41},"pnpm","pnpm dlx skills add steph-frtech\u002Fclaude-code-up --skill python-type-safety","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fmarketplaces\u002Fwshobson\u002Fplugins\u002Fpython-development\u002Fskills\u002Fpython-type-safety\u002FSKILL.md",true,[],[46,53,60,67,74,81],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":18},"01M72Y1BY6X8TX3DS19Y04NEBQ","example","One-line summary of what this skill does","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002Fskills\u002Fexample\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":18},"01M72Y1A38EYR8S9P1MBYDAQTW","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__writing-plans\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":18},"01M72Y174QSV1B5NV1E4KWHQBR","using-git-worktrees","Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__using-git-worktrees\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":18},"01M72Y14SQRHHMKG316HGB2CGK","test-driven-development","Use when implementing any feature or bugfix, before writing implementation code","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__test-driven-development\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":18},"01M72Y127BCPRH3BRKPJC3Q3G2","systematic-debugging","Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__systematic-debugging\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":18},"01M72Y1090GJA6B67KPD60WPHH","subagent-driven-development","Use when executing implementation plans with independent tasks in the current session","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__subagent-driven-development\u002FSKILL.md",[],[]]