python
SolidThis 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 2 days ago MIT
Install
Quality Score: 79/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
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
- 2 days ago
- Language
- TypeScript
- License
- MIT
Bundled in these plugins
Similar Skills
Semantically similar based on skill content — not just same category
AI & Automation Solid
python-typing-patterns
Python type hints and type safety patterns. Triggers on: type hints, typing, TypeVar, Generic, Protocol, mypy, pyright, type annotation, overload, TypedDict.
402 Updated today
aiskillstore Code & Development Listed
python
Python development with ruff, mypy, pytest - TDD and type safety
0 Updated today
lciacci AI & Automation Listed
python-patterns
Pythonic idioms, PEP 8 standards, type hints, and best practices for building robust, efficient, and maintainable Python applications.
3 Updated today
uzysjung