agentleFS
reliable-coding-agentsreliable-coding-agents/reliable-python/skills/writing-maintainable-python/SKILL.md

writing-maintainable-python

Skill1 starsChanged 2 months agoMITView on GitHub

Use when writing or reviewing Python entry points, import-time execution, public type annotations, oversized or multi-purpose functions, or loop-versus-comprehension readability.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Prefer a list comprehension for a pure, straightforward one-pass mapping or filter:

    line 55
  2. Distinctive:

    Use an ordinary loop when the body has side effects, multiple branches, multiple nested clauses, error handling, or needs an explanatory …

    line 62
  3. Very specific:

    Run review-code-quality after changes.

    line 74

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

Writing Maintainable Python

Make execution boundaries and public contracts explicit. Prefer structures whose intent is visible on import, in an editor, and to a static checker.

Practices

IDPracticeEnforcement
PY001Guard executable module codeBare top-level call expressions are warnings
PY002Define main()Organizational guidance
PY003Keep functions small and single-purposePOT04 checks length; responsibility needs review
PY004Annotate public interfacesMissing parameter or return annotations are warnings
PY005Use simple comprehensions when clearerReadability guidance

Entrypoints

Importing a module executes its top-level statements. Put an executable workflow in a typed main() and call it only under the standard guard:

def main() -> None:
    client = connect()
    process(client)


if __name__ == "__main__":
    main()

PY001 deliberately checks only bare calls directly in the module body. An intentional import-time registration call needs an adjacent, specific suppression. Calls used in assignments or decorators are not inferred to be side effects.

Functions and types

Extract a function when it owns a separately nameable rule, phase, or reuse boundary—not merely to reduce line count. POT04 limits a function to 60 code lines; SOLID01 asks whether it has multiple demonstrated reasons to change.

Annotate every public parameter and return value, including *args and **kwargs. self and cls are implicit. Annotations document the contract and enable editor feedback, but Python does not enforce them at runtime; run the project’s configured checker such as mypy or pyright. PY004 checks presence only, not correctness.

Comprehensions

Prefer a list comprehension for a pure, straightforward one-pass mapping or filter:

long_names = [name for name in names if len(name) > 7]

Use an ordinary loop when the body has side effects, multiple branches, multiple nested clauses, error handling, or needs an explanatory name. A comprehension that merely compresses complexity is less maintainable, and it does not establish an input or resource bound.

Common mistakes

  • A guard around several procedural statements: move their orchestration into main().
  • Tiny forwarding helpers with no independent concept: keep cohesive code together.
  • Annotations with no type-check command: add the project’s checker instead of assuming runtime enforcement.
  • Nested comprehensions chosen for brevity: expand them when the reader must simulate control flow.

Run review-code-quality after changes. These practices improve explicitness; they do not replace tests, runtime validation, or architectural review.

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.