python

Solid

This skill should be used when the user works with Python files (.py), asks about "type hints", "protocols", "dataclasses", "async/await", "decorators", or discusses Pythonic patterns and data modeling. Provides patterns for type safety, error handling, data modeling, and async programming.

Code & Development 17 stars 1 forks Updated yesterday MIT

Install

View on GitHub

Quality Score: 79/100

Stars 20%
42
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Python Patterns ## Iron Law > **EXPLICIT IS BETTER THAN IMPLICIT** [3] > > Type-hint every function signature. Name every exception. Use dataclasses over raw > dicts. Python's flexibility is a strength only when boundaries are explicit. ## When This Skill Activates Working with Python codebases, designing typed APIs, modeling data with dataclasses or Pydantic, implementing async code, structuring Python packages. --- ## Type Safety ### Type Hint Everything [4][17][18] ```python # BAD: def process(data, config): ... def process(data: list[dict[str, Any]], config: AppConfig) -> ProcessResult: ... ``` Dropbox's 4M-line mypy migration eliminated entire bug classes [18]. Use `from __future__ import annotations` for forward references [22]. ### Protocols for Structural Typing [5][1] ```python from typing import Protocol class Repository(Protocol): def find_by_id(self, id: str) -> User | None: ... def save(self, entity: User) -> User: ... ``` PEP 544 formalizes duck typing as "static duck typing" — no `implements` required [5]. Any class with matching methods satisfies the Protocol [1]. ### Strict Optional Handling [4][23] PEP 604 `X | Y` syntax replaces verbose `Optional[X]` [23]: ```python def get_name(user: User | None) -> str: return "Anonymous" if user is None else user.name ``` --- ## Error Handling [2][8][9] ```python class AppError(Exception): ... class NotFoundError(AppError): def __init__(self, entity: str, id: str) -> None: su...

Details

Author
dean0x
Repository
dean0x/devflow
Created
10 months ago
Last Updated
yesterday
Language
TypeScript
License
MIT

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category