agentleFS
PraveensenpaiPraveensenpai/karakuri/skills/build-tooling/rust-style-python/SKILL.md

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.

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
  1. Very specific:

    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 …

    line 13
  2. Very specific:

    Use hypothesis for parsers and validators.

    line 48
  3. Distinctive:

    No exceptions for control flow.

    line 71
  4. Very specific:

    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 …

    line 72

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:]))`.

  • main is the only place that maps Err to a log line and an exit code: 0 ok, 1 runtime error, 2 usage/validation error, 130 interrupted.
  • One last-resort try/except BaseException in main logs the full traceback and returns nonzero. It is a safety net, never normal control flow.

10. Logging

  • Structured logging (logging with extra= key/values, or structlog).
  • Log each error once, at the boundary that handles it, not at every layer it passes through.
  • No print for 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

  • pytest tests for every Err path, not just the happy path: malformed input, missing file, permission denied, timeout, partial failure, empty input, huge input, unicode edge cases.
  • Use hypothesis for parsers and validators.

13. Output Format

Deliver in this order:

  1. Failure-mode analysis (the pre-code table)
  2. Error type definitions
  3. Result/Option helpers (skip if using returns)
  4. Boundary functions (I/O, parsing) returning Result
  5. Pure core logic
  6. main with exit-code mapping
  7. pyproject.toml tooling config
  8. Tests
  9. A short failure-mode table: failure → error variant → how it's handled

14. Hard Constraints

  • No try/except in core logic. It lives only in boundary functions and main.
  • No exceptions for control flow.
  • 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 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 main with 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.