Configs2026年3月29日·1 分钟阅读

Cursor Rules: Python — Clean Code with AI

Cursor rules for Python development. Enforces PEP 8 style, type hints, docstrings, pytest patterns, and modern Python 3.12+ idioms.

TO
TokRepo精选 · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

Create .cursor/rules/python.mdc in your project root.


介绍

Configures Cursor AI to write clean, idiomatic Python code. Enforces PEP 8 style, type annotations, comprehensive docstrings, and modern Python patterns.

Best for: Python developers using Cursor IDE Works with: Cursor


Rules Include

Style

  • PEP 8 compliance with 88-char line length (Black formatter)
  • Type hints on all function signatures
  • Google-style docstrings
  • f-strings over .format() or %

Patterns

  • Dataclasses and Pydantic models over plain dicts
  • Context managers for resource handling
  • Generators for large data processing
  • pathlib.Path over os.path

Testing

  • pytest with fixtures and parametrize
  • Arrange-Act-Assert pattern
  • Mock external dependencies, not internal logic

Modern Python (3.12+)

  • Match statements for complex conditionals
  • type keyword for type aliases
  • Exception groups with except*

🙏

来源与感谢

Curated from the cursor.directory community. Based on Python community best practices.

相关资产