python-patterns

Applies Pythonic idioms, type hints, and PEP 8 standards to Python code.

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill python-patterns-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-patterns
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/python-patterns
Command: npx skills add https://github.com/Femad-6/my-skills --skill python-patterns-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Python code that is readable, maintainable, and idiomatic requires consistent application of PEP 8 standards, type hints, and established patterns, which is hard to enforce across writing, reviewing, and refactoring work. ## Core Features & Use Cases - Idiomatic Patterns: Covers EAFP error handling, context managers, comprehensions, generators, decorators, and dataclasses with concrete code examples. - Type Hints & Concurrency: Guides modern type annotations, Protocol-based duck typing, and choosing between threading, multiprocessing, and async/await. - Tooling & Project Layout: Provides pyproject.toml configuration for black, ruff, mypy, and pytest plus standard package structure. - Use Case: When refactoring a legacy module, apply the anti-patterns checklist to replace mutable default arguments, bare except clauses, and string concatenation in loops with correct idioms. ## Quick Start Ask the assistant to review your Python file and refactor it using python-patterns idioms, type hints, and PEP 8 standards.

Frequently Asked Questions about python-patterns

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

FAQPage Schema
How do I write idiomatic Python code following PEP 8?

Idiomatic Python prioritizes readability, explicit behavior, and EAFP-style exception handling over condition checking. Use comprehensions for simple transformations, context managers for resources, f-strings for formatting, and type hints on function signatures.

When should I use threading vs multiprocessing vs asyncio in Python?

Use threading with ThreadPoolExecutor for I/O-bound tasks, multiprocessing with ProcessPoolExecutor for CPU-bound work that must bypass the GIL, and async/await with asyncio for high-concurrency network I/O such as fetching many URLs.

How do I add type hints to Python functions?

Annotate parameters and return types using built-in generics like list[str] and dict[str, int] on Python 3.9+, or the typing module on earlier versions. Use Optional for nullable returns, TypeVar for generics, and Protocol for duck-typed interfaces.

What are common Python anti-patterns to avoid?

Avoid mutable default arguments, bare except clauses, comparing to None with ==, checking types with type() instead of isinstance, star imports, and string concatenation in loops. Each has a standard replacement such as None defaults and str.join.

When should I use dataclasses instead of regular classes?

Use @dataclass for data containers that need automatic __init__, __repr__, and __eq__ without boilerplate. Add __post_init__ for validation, and use NamedTuple when you need immutable lightweight records.