agentleFS
andr-caandr-ca/agentharness/.claude/skills/python-conventions/SKILL.md

python-conventions

Skill1 starsChanged 2 months agoMITView on GitHub

Use when writing or reviewing Python code — naming conventions, type hints, common pitfalls (mutable defaults, bare except, is-vs-==), and testing structure.

7 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 0

    Distinctive

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

    Use them on function parameters and returns.

    line 36

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “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

Python Conventions

This file is self-contained for day-to-day use. Deeper reference (needs the full harness checkout, not just this skill — these aren't bundled here since they're documentation, not something this skill runs): languages/python/CONVENTIONS.md (complete examples) and languages/python/COPILOT_INSTRUCTIONS.md (general agent operating principles for Python repos — inspect before changing, scope discipline, never claim a command passed without running it).

Naming

  • snake_case — functions, variables. PascalCase — classes. UPPER_SNAKE_CASE — module-level constants.
  • Single underscore prefix for private (_internal); avoid double underscore except for genuine name-mangling needs.
  • Exceptions: PascalCase + Error/Exception suffix, specific not generic (ValidationError, not BadThing).

Imports & structure

Standard library → third-party → local, each group separated by a blank line. Absolute imports over relative. No from module import *.

Type hints

Use them on function parameters and returns. Match syntax to the project's minimum Python version — check requires-python in pyproject.toml before using list[str] (3.9+), X | None (3.10+), or match/case (3.10+). Don't silently raise the minimum version.

Pitfalls to catch in review

# Mutable default argument — persists across calls, shared state bug
def f(item, container=[]):  # WRONG
def f(item, container=None):  # RIGHT — default to None, create inside

# Bare/broad except — swallows KeyboardInterrupt, hides real errors
except:  # WRONG
except Exception:  # still too broad, usually
except ValueError as e:  # RIGHT — catch what you expect

# `is` for value comparison — checks identity, not equality
if user_id is 5:  # WRONG
if user_id == 5:  # RIGHT (== for values, `is` only for None/True/False)

Testing

tests/ directory, test_*.py files, test_* functions, pytest fixtures for setup. See patterns/testing/TDD.md for the broader methodology — this skill covers Python-specific structure only.

Formatting & tooling

Defer to the project's pyproject.toml — don't impose Black/Ruff defaults over an existing configured formatter/linter. If unconfigured: Black or ruff format (88-char lines), ruff check, mypy for typing, pytest for tests.

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.