| name | python-style |
| description | Apply personal Python code style — stdlib-first, single quotes, low nesting, named ANSI constants, performance-driven, vertical kwarg alignment. Use when writing or editing Python (.py files), setting up pyproject.toml, choosing between implementations, or naming tests. |
Python Style
Rules
Dependencies
Structure
- Keep nesting shallow: 2 levels is the usual ceiling, 3 the hard maximum.
- Use early return /
continue to flatten.
- If early return won't work, extract a helper method.
- Never write banner comments (
# ===== Section ===== etc.).
Quoting
Performance
- Performance is a first-class concern. When multiple implementations are plausible, benchmark them.
- Benchmark options, in order of preference:
bench.py from laser-prynter — for comparing multiple Python implementations on the same input set.
ipython with %timeit — for ad-hoc one-liners.
hyperfine — for whole-process / CLI comparisons.
- Prefer
'sep'.join([...]) over repeated += string append in loops.
- Prefer
yield (generator) over building a list with for+append then returning it.
Constants
Tests
- Name tests after what they test, not after spec numbers, ticket IDs, or section labels.
- Good:
test_parses_iso_date_with_offset
- Bad:
test_REQ_042_3, test_spec_section_2_1
Vertical alignment of kwargs
- I prefer aligned
= in long kwarg lists. Ruff's formatter strips these spaces.
- Workaround: keep the file in
tool.ruff.exclude (see template). The file is still linted only if removed from exclude — but format won't touch alignment.
- Example shape:
return cls(
session_id = d.get('session_id', ''),
transcript_path = d.get('transcript_path', ''),
cwd = d.get('cwd', ''),
)
Project setup
Drop pyproject-template.toml (in this skill dir) into new repos as the starting point. It encodes:
mypy strict mode with disallow_untyped_defs
ruff check with single-quote enforcement (flake8-quotes)
ruff format with quote-style = "preserve" so existing single quotes survive
- Excludes for
.claude/, .venv/, and any dir holding vertically-aligned code
Checklist before declaring done