python-standards
Python code quality standards (PEP 8, type hints, docstrings). Use when writing Python code.
Installation
Suivez les instructions du dépôt pour votre agent. Consultez les fichiers et dépendances avant l’installation.
Voir la source ↗GuidesInstructions
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
Exemples
Consultez les exemples du dépôt source.
Voir la source ↗Historique source
- Date d’indexation
- 2026-01-20
- Mise à jour de l’index
- 2026-01-26
- Branch
- main
Les dates concernent ce répertoire. Consultez le dépôt pour l’historique du code.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!