python-standards
Python code quality standards (PEP 8, type hints, docstrings). Use when writing Python code.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Python Standards Skill
Python code quality standards for autonomous-dev project.
See: code-examples.md for complete code examples See: templates.md for organization templates
When This Activates
- Writing Python code
- Code formatting
- Type hints
- Docstrings
- Keywords: "python", "format", "type", "docstring"
Code Style (PEP 8 + Black)
| Setting | Value |
|---|---|
| Line length | 100 characters |
| Indentation | 4 spaces (no tabs) |
| Quotes | Double quotes |
| Imports | Sorted with isort |
black --line-length=100 src/ tests/
isort --profile=black --line-length=100 src/ tests/
Type Hints (Required)
Rule: All public functions must have type hints on parameters and return.
def process_file(
input_path: Path,
output_path: Optional[Path] = None,
*,
max_lines: int = 1000
) -> Dict[str, any]:
"""Type hints on all parameters and return."""
pass
See: code-examples.md#type-hints for complete examples
Docstrings (Google Style)
Rule: All public functions/classes need docstrings with Args, Returns, Raises.
def process_data(data: List[Dict], *, batch_size: int = 32) -> ProcessResult:
"""Process data with validation.
Args:
data: Input data as list of dicts
batch_size: Items per batch (default: 32)
Returns:
ProcessResult with items and metrics
Raises:
ValueError: If data is empty
"""
See: code-examples.md#docstrings-google-style
Error Handling
Rule: Error messages must include context + expected + docs link.
# ✅ GOOD
raise FileNotFoundError(
f"Config file not found: {path}\n"
f"Expected: YAML with keys: model, data\n"
f"See: docs/guides/configuration.md"
)
# ❌ BAD
raise FileNotFoundError("File not found")
See: code-examples.md#error-handling
Naming Conventions
| Type | Convention | Example |
|---|---|---|
| Classes | PascalCase | ModelTrainer |
| Functions | snake_case | train_model() |
| Constants | UPPER_SNAKE | MAX_LENGTH |
| Private | _underscore | _helper() |
Best Practices
-
Keyword-only args - Use
*for clarity -
Pathlib - Use
Pathnot string paths -
Context managers - Use
withfor resources - Dataclasses - For configuration objects
# Keyword-only args
def train(data: List, *, learning_rate: float = 1e-4):
pass
# Pathlib
config = Path("config.yaml").read_text()
See: code-examples.md#best-practices
Code Quality Commands
flake8 src/ --max-line-length=100 # Linting
mypy src/[project_name]/ # Type checking
pytest --cov=src --cov-fail-under=80 # Coverage
Key Takeaways
- Type hints - Required on all public functions
- Docstrings - Google style, with Args/Returns/Raises
- Black formatting - 100 char line length
- isort imports - Sorted and organized
- Helpful errors - Context + expected + docs link
- Pathlib - Use Path not string paths
-
Keyword args - Use
*for clarity - Dataclasses - For configuration objects
Related Files
- code-examples.md - Complete Python code examples
- templates.md - File organization templates
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-01-26
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!