python-patterns
Pythonic idioms, PEP 8 standards, type hints, and best practices for building robust, efficient, and maintainable Python applications.
Security Assessment
About python-patterns
This skill is a reference guide to idiomatic Python patterns, PEP 8 standards, type hints, and best practices for building robust, efficient, and maintainable applications. It addresses the common problem of code that works but is not Pythonic by codifying the conventions and design patterns an assistant should apply when writing, reviewing, or refactoring Python.
The guidance covers core principles (readability, explicit over implicit, EAFP over LBYL), a thorough treatment of type hints (basic annotations, modern 3.9+ built-in generics, type aliases and TypeVar, Protocol-based structural typing), error-handling patterns (specific exception handling, exception chaining with `raise ... from`, custom exception hierarchies), context managers (resource management, `@contextmanager`, and class-based managers), and comprehensions and generators (including generator functions for lazy evaluation of large data). Each topic is illustrated with contrasting good and bad code examples.
It is aimed at Python developers and reviewers, and at AI assistants generating or refactoring Python, who want consistent, idiomatic output. It activates when writing new code, reviewing code, refactoring, or designing packages and modules. It is a static reference with no execution, tools, or side effects.
FAQ
What topics does the skill cover?
Core Pythonic principles, type hints (including modern 3.9+ and Protocols), error handling and custom exception hierarchies, context managers, and comprehensions and generators.
When does it activate?
When writing new Python code, reviewing code, refactoring existing code, or designing Python packages and modules.
Does it enforce a specific Python version style?
It shows both modern 3.9+ built-in generic syntax (list[str], dict[str, int]) and the older typing-module equivalents for 3.8 and earlier.
Does it run linters or modify files?
No. It is a guidance reference with paired good/bad examples; it does not execute tools or change code by itself.
Who is the intended audience?
Python developers and reviewers, and assistants generating or refactoring Python, who want idiomatic, maintainable output aligned with PEP 8.
Install python-patterns
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
affaan-m/ecc