diff options
| author | main <main@swarm.moe> | 2026-05-19 12:20:12 -0400 |
|---|---|---|
| committer | main <main@swarm.moe> | 2026-05-19 12:20:12 -0400 |
| commit | 8e748db6ba0b52091fc4c3664c0bfba5c7185e68 (patch) | |
| tree | 13720f4651ae6354b3e0ba5643bcd2ab29598f9c /skills/exterminate-slop/references/languages/python.md | |
| parent | 372d366f541f4560a304d4d374bebc31aec6e8c3 (diff) | |
| download | rust_starter-8e748db6ba0b52091fc4c3664c0bfba5c7185e68.zip | |
Generalize exterminate-slop skill
Diffstat (limited to 'skills/exterminate-slop/references/languages/python.md')
| -rw-r--r-- | skills/exterminate-slop/references/languages/python.md | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/skills/exterminate-slop/references/languages/python.md b/skills/exterminate-slop/references/languages/python.md new file mode 100644 index 0000000..023f2d6 --- /dev/null +++ b/skills/exterminate-slop/references/languages/python.md @@ -0,0 +1,49 @@ +# Python + +Use this note for Python source scopes. It sharpens the generic extermination pass; it is not a style guide. + +## Manifest + +Source files are `*.py` under the requested subtree. Exclude generated files, vendored code, build output, virtualenvs, fixtures, snapshots, notebooks, and migration dumps unless the user explicitly includes them. Include tests when they expose duplicated construction, domain shape, or behavior-preservation evidence. + +## Navigation + +Use `rg`, the project's type checker, tests, and runtime entrypoints together. Python's semantic truth is often distributed across constructors, call sites, fixtures, protocols, and serialization edges; chase live construction and consumption paths before deciding an abstraction. Track import cycles and package boundaries before moving code. + +## Static Posture + +Pretend Python is statically compiled. Lean on precise annotations, `mypy`/`pyright` or `ty`, `typing` machinery, `Protocol`, `NewType`, `Literal`, `Final`, `TypeAlias`, generics, overloads, dataclasses, enums, and exhaustive local structure. Runtime validation is not a virtue by default; it is often defensive bloat. Add runtime checks only at real trust boundaries or where the program already depends on dynamic validation. + +## Deslopping Moves + +Move semantics out of anonymous primitives and into named static structure. Strings used as identifiers, slugs, modes, statuses, units, paths, URLs, and external keys should become `NewType`, `Literal` unions, enums, dataclasses, type aliases, or small value objects according to the strength of the invariant. Dict soup and tuple soup should become typed records: dataclasses, `NamedTuple`, `TypedDict` at transport edges, or explicit domain objects. + +Collapse repeated parse, normalize, default-fill, render, serialize, authorize, query, and error-shaping logic into one owner. Prefer type-directed constructors, pure conversion functions, protocols, table-driven dispatch, and explicit domain modules over repeated "simple" helper code. Centralize boundary coercion; inside the program, trust the typed representation instead of rechecking it everywhere. + +Bias toward code volume reduction when it increases semantic density. Delete defensive glue made obsolete by types, duplicate fixture builders, repeated `if key in dict` ladders, parallel lists, ceremonial wrappers, scattered casts, redundant `assert x is not None`, and sprawling optional bags. A compact typed representation is better than ten "safe" guards synchronized by anxiety. + +## Fail Fast + +Aggressively remove checks that static structure, construction path, or local dominance already proves unnecessary. Purge ceremony around irrecoverable errors. If missing data means the program is broken, crash at the point of contradiction instead of inventing a worthless dummy. Do not call `.get(key, default)` when the default has no honest semantics. Do not catch exceptions merely to rewrap, log-and-limp, return `None`, or preserve a doomed control path. Fail early, loudly, and close to the violated invariant. + +## Python-Specific Suspects + +Scrutinize `dict[str, Any]`, untyped dicts, tuple returns, string tags, magic constants, `None` sentinels, boolean flags, loose `**kwargs`, repeated `TypedDict` shapes, dataclasses with many optionals, scattered `cast`, ad-hoc path/string handling, repeated fixture factories, and `isinstance` chains over the same latent variant. + +Scrutinize boundaries separately. JSON, SQL rows, environment variables, argparse, HTTP payloads, pandas frames, and third-party SDK responses may arrive as primitives or dicts, but boundary coercion should happen once. Do not drag runtime paranoia into already-typed internal code. + +## Modernization Posture + +Default to zero backward compatibility with older Python versions. If the review is global in scope, and dependency constraints do not forbid it, upgrade the project to the latest viable Python version. If it can be upgraded, it should be. + +Use modern Python features when the project permits them: `dataclass(slots=True, frozen=True)`, structural pattern matching, `StrEnum`, `typing` improvements, `Protocol`, `Self`, `Literal`, precise generics, `|` unions, `TypeGuard`/`TypeIs`, and `Final`. Prefer stdlib and static-analysis-visible constructs. + +Astral tooling is mandatory doctrine: `uv`, `ruff`, and `ty` should be installed or introduced unless the repo has an explicit incompatible toolchain reason. Use Ruff's `UP` rules to modernize syntax and erase compatibility husks. Add dependencies only when they delete more machinery than they introduce. + +## Verification + +After edits, run the narrowest meaningful tests for the touched surface, then widen if the abstraction crosses packages. Run the project's formatter, linter, and type checker when present. Treat `ty`/mypy/pyright, Ruff, and tests as evidence, not as a substitute for the extermination ledger. + +## Avoid + +Do not launder defensive programming as rigor. Do not preserve dict soup because "Python is dynamic." Do not keep `None`/bool/string encodings when a named static representation would compress the truth. Do not create baroque class hierarchies without invariant pressure. Do not leave five small helpers when one typed domain object would annihilate them. |