Agent skill
python-code-style
Professional Python code style enforcement for generation and review. When Claude needs to work with Python code for: (1) Generating Python code, scripts, functions, or classes, (2) Reviewing or auditing existing Python code, (3) Refactoring Python code, (4) Creating .py files, or any Python coding tasks.
Install this agent skill to your Project
npx add-skill https://github.com/pillarliang/python-code-style/tree/main/skills/python-code-style
SKILL.md
Python Code Style Guide
When generating Python code, strictly follow these professional Python style guidelines. This skill provides comprehensive coding standards based on industry best practices.
Quick Reference
Naming Conventions
| Type | Convention | Example |
|---|---|---|
| Module | lower_with_under |
my_module.py |
| Package | lower_with_under |
my_package |
| Class | CapWords |
MyClass |
| Exception | CapWords + Error |
MyError |
| Function | lower_with_under |
my_function() |
| Method | lower_with_under |
my_method() |
| Constant | CAPS_WITH_UNDER |
MAX_VALUE |
| Variable | lower_with_under |
my_var |
| Parameter | lower_with_under |
my_param |
| Internal | _leading_under |
_internal_var |
Essential Formatting Rules
- Indentation: 4 spaces (no tabs)
- Line length: 80 characters max (exceptions: imports, URLs, pathnames)
- Blank lines: 2 between top-level definitions, 1 between methods
- Imports: One per line, grouped (stdlib → third-party → local)
- Strings: Use
"for strings,"""for docstrings - No semicolons at end of lines
- No backslash for line continuation; use parentheses
Docstring Format
def function_name(arg1: str, arg2: int = 0) -> bool:
"""Short one-line summary.
Longer description if needed. Explain what the function
does, not how it does it.
Args:
arg1: Description of arg1.
arg2: Description of arg2. Defaults to 0.
Returns:
Description of return value.
Raises:
ValueError: When arg1 is empty.
"""
Import Order
# 1. Standard library imports
import os
import sys
# 2. Third-party imports
import numpy as np
import pandas as pd
# 3. Local application imports
from myproject import mymodule
Detailed References
For comprehensive rules, read these reference files as needed:
- references/language-rules.md: Lint, imports, exceptions, global state, comprehensions, generators, lambda, type annotations
- references/style-rules.md: Formatting, whitespace, comments, strings, logging, statements
- references/naming-conventions.md: Complete naming rules with examples
- references/docstrings.md: Full docstring format for modules, classes, functions
Code Generation Checklist
When generating Python code, ensure:
- All names follow the naming conventions table above
- All public functions/methods have proper docstrings with Args/Returns/Raises
- Imports are properly ordered and formatted
- Line length does not exceed 80 characters
- 4-space indentation is used consistently
- Type hints are included for function signatures
- Exceptions inherit from appropriate base classes and end with
Error - No mutable default arguments (use
Noneinstead) - Use
is/is notforNonecomparisons - Prefer list/dict/set comprehensions over
map()/filter()
Code Review Checklist
When reviewing Python code, check for these issues and provide specific feedback:
Naming Issues
- Variables/functions not using
snake_case - Classes not using
CapWords - Constants not using
CAPS_WITH_UNDER - Internal items missing
_leading_underscore - Unclear or non-descriptive names
Documentation Issues
- Missing or incomplete docstrings
- Docstrings lacking Args/Returns/Raises sections
- Outdated docstrings not matching actual behavior
- Missing module-level docstring
Style Issues
- Lines exceeding 80 characters
- Incorrect indentation (not 4 spaces)
- Wrong import ordering (should be: stdlib → third-party → local)
- Missing blank lines between top-level definitions
- Using tabs instead of spaces
Code Quality Issues
- Mutable default arguments (e.g.,
def func(items=[])) - Using
==or!=forNonecomparisons - Using
map()/filter()instead of comprehensions - Missing type hints on public functions
- Bare
except:clauses without specific exception types - Overly broad exception handling
Review Output Format
When reviewing code, provide feedback in this format:
## Code Review Summary
### ✅ What's Good
- [List positive aspects]
### ⚠️ Issues Found
#### Issue 1: [Category] - [Brief Description]
- **Location**: Line X
- **Problem**: [Description]
- **Suggestion**: [How to fix]
- **Example**:
```python
# Before
[problematic code]
# After
[corrected code]
📊 Overall Assessment
- Style Compliance: X/10
- Documentation: X/10
- Code Quality: X/10
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
handoff
Compact the current conversation into a handoff document for another agent to pick up.
obsidian-vault
Search, create, and manage notes in the Obsidian vault with wikilinks and index notes. Use when user wants to find, create, or organize notes in Obsidian.
scaffold-exercises
Create exercise directory structures with sections, problems, solutions, and explainers that pass linting. Use when user wants to scaffold exercises, create exercise stubs, or set up a new course section.
edit-article
Edit and improve articles by restructuring sections, improving clarity, and tightening prose. Use when user wants to edit, revise, or improve an article draft.
git-guardrails-claude-code
Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.
migrate-to-shoehorn
Migrate test files from `as` type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace `as` in tests, or needs partial test data.
Didn't find tool you were looking for?