Skip to content

Instantly share code, notes, and snippets.

@felipecustodio
Created April 30, 2025 18:56
Show Gist options
  • Select an option

  • Save felipecustodio/08fee0378441a685d8beff0634ae112d to your computer and use it in GitHub Desktop.

Select an option

Save felipecustodio/08fee0378441a685d8beff0634ae112d to your computer and use it in GitHub Desktop.
Cursor rules for my Python projects
## 1 · Core Principles
- **Mirror the repo** – follow existing structure, naming, and any code-style overrides in `pyproject.toml`.
- **Plan → edit → verify** – outline intent in chat, modify only planned sections, then run Make targets to lint, type-check, and test.
- **Read-only Git** – Can inspect diffs and logs but must **not** commit, push, or manipulate branches.
## 2 · Typing & Pydantic
- All public symbols are fully annotated; avoid `Any` unless strictly justified.
- Use modern syntax (`list[int]`, `X | Y`).
- Data objects are **Pydantic models** with `strict=True` and `Strict*` field types for safe coercion.
- Code must pass **Pyright** with zero errors.
## 3 · Asynchronous Code
- Write non-blocking `async def` / `await` functions
- Handle cancellation and resource cleanup explicitly.
## 4 · Tooling Checks
- Run **only** the Makefile targets (e.g., `make lint`, `make types`, `make test`); each target orchestrates Docker for consistent environments.
- Never call bare `python …`; the Makefile encodes paths and container flags.
- Lint must be clean with **Ruff**.
- Type-check must be clean with **Pyright**.
- Before any local command, activate the current virtual environment for the current shell.
## 5 · Diff Discipline
- Touch only files relevant to the task at hand; no drive-by refactors or mass formatting.
- If you spot an unrelated issue, leave a TODO, only if very critical.
## 6 · Comments & Docs
- Minimal, purposeful comments: explain *why*, not *what*, only when just the code is not enough.
- Keep existing docs unless incorrect; update docstrings to match changed behavior.
- Never add conversational AI-style prose.
## 7 · Workflow
1. **Understand** – skim code, diffs, tests; ask clarifying questions when unsure.
2. **Plan** – outline the exact edits and affected files.
3. **Act** – apply scoped edits; run `make lint types test`, as outlined in the Makefile.
4. **Verify** – proceed only when Ruff, Pyright, and all tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment