rust-style-python
Skill0 starsChanged 59 days agoMITView on GitHub
Enforces Rust/Go-style error handling for Python scripts and modules, where failures are explicit typed values instead of surprise exceptions mid-run. Mandates Result/Option types, boundary-only exception conversion, exhaustive matching, structured error context, exit-code mapping in main, and mypy --strict compliance. Activate for any Python code touching files, network, subprocesses, parsing, or concurrency where reliability matters.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rules/AGENTS.mdAGENTS.md
- kurokoSkill
- tayoriSkill
- xerjSkill
- aesthetic-readme-craftSkill
- cli-builderSkill
- codebase-digestSkill
- git-release-craftSkill
- git-repo-craftSkill
- karakuriSkill
- python-clean-codeSkill
- rust-clean-codeSkill
- systematic-code-verificationSkill
- compose-clean-codeSkill
- bash-clean-codeSkill
- tui-designSkill
- frontend-designSkill
- web-design-guidelinesSkill
- unslopSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Write Python the way Rust and Go are written: every failure path is explicit, typed, and handled at the int returns an exit code, and the …
- Very specific: line 48
Use hypothesis for parsers and validators.
- Distinctive: line 71
No exceptions for control flow.
- Very specific: line 72
If a user requirement conflicts with these rules (for example, they want a quick sys.exit in the middle of a helper), point it out and …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
rust-style-python Skill: Explicit, Typed Error Handling
Write Python the way Rust and Go are written: every failure path is explicit, typed, and handled at the intreturns an exit code, and the entry isif name == "main": raise SystemExit(main(sys.argv[1:]))`.
mainis the only place that mapsErrto a log line and an exit code:0ok,1runtime error,2usage/validation error,130interrupted.- One last-resort
try/except BaseExceptioninmainlogs the full traceback and returns nonzero. It is a safety net, never normal control flow.
10. Logging
- Structured logging (
loggingwithextra=key/values, orstructlog). - Log each error once, at the boundary that handles it, not at every layer it passes through.
- No
printfor diagnostics.
11. Typing and Tooling
Full type hints everywhere, no Any unless justified in a comment. Code must pass mypy --strict (or pyright --strict) and ruff.
[tool.mypy]
strict = true
warn_unreachable = true
[tool.ruff]
target-version = "py312"
[tool.ruff.lint]
select = ["E", "F", "B", "BLE", "TRY", "ERA", "S", "SIM", "UP", "RET", "PL", "ANN"]12. Tests
pytesttests for everyErrpath, not just the happy path: malformed input, missing file, permission denied, timeout, partial failure, empty input, huge input, unicode edge cases.- Use
hypothesisfor parsers and validators.
13. Output Format
Deliver in this order:
- Failure-mode analysis (the pre-code table)
- Error type definitions
- Result/Option helpers (skip if using
returns) - Boundary functions (I/O, parsing) returning
Result - Pure core logic
mainwith exit-code mappingpyproject.tomltooling config- Tests
- A short failure-mode table: failure → error variant → how it's handled
14. Hard Constraints
- No
try/exceptin core logic. It lives only in boundary functions andmain. - No exceptions for control flow.
- If a user requirement conflicts with these rules (for example, they want a quick
sys.exitin the middle of a helper), point it out and propose the closest compliant alternative rather than silently breaking the rules. - Match the scope to the task: a 30-line script still gets typed errors and a
mainwith exit codes, but does not need an elaborate framework. Skip sections that genuinely don't apply (no concurrency means no concurrency section) and say so.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

