Enforce modern Python development practices with strict formatting, typing, and documentation standards for clean, maintainable codebases
Enforce strict development standards for Python projects, ensuring code quality, consistency, and maintainability through modern tooling and best practices.
When working on Python projects with this skill:
1. **Always use English** for all code, comments, documentation, strings, and log messages
2. **Format with 2-space indentation** consistently throughout the codebase
3. **Use full English words** for all identifiers (variables, functions, classes) - no abbreviations
4. **Apply type hints** to all function signatures without exception
5. **Leverage modern Python features**: f-strings, pathlib, dataclasses
Comments must explain **why**, not what. For complex logic, clarify both the "what" and provide examples.
```python
TIMEOUT = 10
COMPLEX_REGEX = r',(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)'
TIMEOUT = 10
def add(a: int, b: int) -> int:
return a + b
def add(a: int, b: int) -> int:
return a + b
```
All function signatures must include complete type hints:
```python
from pathlib import Path
from dataclasses import dataclass
def process_file(file_path: Path, timeout: int = 10) -> dict[str, str]:
"""Process a file and return parsed data."""
pass
@dataclass
class Config:
timeout: int
retries: int
base_url: str
```
Always use f-strings:
```python
message = f"Processing {file_count} files in {duration}s"
message = "Processing {} files in {}s".format(file_count, duration)
message = "Processing %d files in %ds" % (file_count, duration)
```
Always use `pathlib.Path`:
```python
from pathlib import Path
config_path = Path("config") / "settings.json"
if config_path.exists():
content = config_path.read_text()
import os
config_path = os.path.join("config", "settings.json")
if os.path.exists(config_path):
with open(config_path) as f:
content = f.read()
```
Use Python's built-in `assert` statement:
```python
def test_parser():
result = parse_input("test")
assert result == expected_value
assert len(result.items) > 0
```
Use standard examples when possible:
```bash
uv run pytest
uv run pytest tests/test_parser.py
uv run pytest -v
```
1. **Plan First**: For complex tasks, propose a step-by-step implementation plan before writing code
2. **Test Coverage**: Write pytest tests for all new functionality
3. **Atomic Commits**: Keep commits small and focused on a single change
4. **Clean Implementation**: If a solution becomes messy, reset and re-implement cleanly rather than patching
5. **Format Before Commit**: Run `ruff` formatting on all modified files before finalizing
Before completing any task, verify:
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/python-development-standards/raw