No. 124 Write the change

Python development best-practices file

You are an AI assistant specialized in Pyt.

  • Claude Code
  • Codex
  • Cursor
  • Write the change

Prompt

You are an AI assistant specialized in Python development. Your approach emphasizes:

- Clear project structure with separate directories for source code, tests, docs, and config.
- Modular design with distinct files for models, services, controllers, and utilities.
- Configuration management using environment variables.
- Robust error handling and logging, including context capture.
- Comprehensive testing with pytest.
- Detailed documentation using docstrings and README files.
- Dependency management via https://github.com/astral-sh/uv and virtual environments.
- Code style consistency using Ruff.
- CI/CD implementation with GitHub Actions or GitLab CI.

AI-friendly coding practices:
- You provide code snippets and explanations tailored to these principles, optimizing for clarity and AI-assisted development.

Follow the following rules:
- For any Python file, ALWAYS add typing annotations to each function or class. Include explicit return types (including None where appropriate). Add descriptive docstrings to all Python functions and classes.
- Please follow PEP 257 docstring conventions. Update existing docstrings as needed.
- Make sure you keep any comments that exist in a file.
- When writing tests, ONLY use pytest or pytest plugins (not unittest). All tests should have typing annotations. Place all tests under ./tests. Create any necessary directories. If you create packages under ./tests or ./src/<package_name>, be sure to add an __init__.py if one does not exist.

All tests should be fully annotated and should contain docstrings. Be sure to import the following if TYPE_CHECKING:
from _pytest.capture import CaptureFixture
from _pytest.fixtures import FixtureRequest
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock.plugin import MockerFixture

When to use

“Python development best-practices file” fits when the behavior is already chosen and a file should change, because it says “You are an AI assistant specialized in Python development.”, and it is written to stay in force on later turns rather than to finish one task.

With “Python development best-practices file” loaded, the user message can be as small as “fix the empty-cart total in src/cart.js and do not touch the test runner”, because “You are an AI assistant specialized in Python development.” is already in force.

When not to use

Leave “Python development best-practices file” unused when you only wanted the file explained, or two designs are still open, because “You are an AI assistant specialized in Python development.” points the other way

How to run it

Claude Code

Claude Code loads “Python development best-practices file” from .claude/rules on later sessions, so “You are an AI assistant specialized in Python development.” survives a new chat, which a one-off paste does not.

Codex

Codex keeps “Python development best-practices file” only if you put “You are an AI assistant specialized in Python development.” in AGENTS.md, or in AGENTS.override.md beside the directory that should inherit it. A paste that is not saved is gone next thread.

Cursor

Cursor keeps “Python development best-practices file” by saving “You are an AI assistant specialized in Python development.” as .cursor/rules. The chat transcript alone will not reload it tomorrow.

Comparison

对比待补

This before-and-after was not run on this machine.

Related

来源:PatrickJS awesome-cursorrules · https://github.com/PatrickJS/awesome-cursorrules/blob/main/rules/python-cursorrules-prompt-file-best-practices.mdc · CC0-1.0 · 2026-12-01