python-patterns

Applies Pythonic idioms, type hints, and PEP 8 standards when writing or reviewing Python code.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill python-patterns-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-patterns
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/python-patterns
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill python-patterns-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python codebases often accumulate unidiomatic patterns, missing type annotations, and inconsistent error handling that reduce readability and maintainability. This Skill provides a comprehensive reference of Pythonic patterns so code is written and reviewed against established best practices from the start. ## Core Features & Use Cases - Idiomatic Code Patterns: Covers EAFP error handling, context managers, comprehensions, generators, decorators, and dataclasses with concrete good/bad examples. - Type Hints & Modern Python: Guidance on type annotations, Protocol-based duck typing, TypeVar generics, and Python 3.9+ built-in generic types. - Concurrency & Performance: Patterns for threading, multiprocessing, async/await, slots memory optimization, and avoiding common performance pitfalls. - Use Case: When refactoring a legacy Python module, activate this Skill to replace bare except clauses with specific exception handling, convert manual loops to comprehensions, and add proper type hints throughout. ## Quick Start Review my Python module and refactor it to follow Pythonic patterns with proper type hints and error handling.

Frequently Asked Questions about python-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write Pythonic code following PEP 8?▼

Pythonic code prioritizes readability, uses explicit over implicit behavior, and follows EAFP exception handling. Use list comprehensions for simple transformations, context managers for resources, and f-strings for formatting.

How to add type hints to Python functions?▼

Annotate function signatures with parameter and return types using built-in generics like list[str] in Python 3.9+, or typing module equivalents for earlier versions. Use Optional for nullable returns and TypeVar for generic functions.

Should I use threading or multiprocessing in Python?▼

Use ThreadPoolExecutor for I/O-bound tasks like network requests, and ProcessPoolExecutor for CPU-bound computations. For high-concurrency I/O, async/await with asyncio and aiohttp is the preferred pattern.

Why are mutable default arguments dangerous in Python?▼

Mutable defaults like def f(items=[]) are evaluated once at definition time and shared across calls, causing unexpected state accumulation. Use None as the default and create a new list inside the function body instead.

When should I use dataclasses vs NamedTuple in Python?▼

Use dataclasses for mutable data containers needing validation via __post_init__ and default factories. Use NamedTuple for immutable records with fixed fields, such as coordinates or simple value objects.