Files
cattleTransportation/.cursor/rules/languages/python.mdc
2025-11-04 09:38:19 +08:00

20 lines
808 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: 该规则解释了 Python 编码、最佳实践、 整洁高效的代码模式.
globs: **/*.py
alwaysApply: false
---
# Python 规则
- 遵循 PEP 8 风格指南和命名约定
- 使用类型注解增强代码可读性和类型安全性
- 使用虚拟环境管理依赖:
- 优先使用 `venv` 或 `poetry` 进行环境隔离
- 使用 `requirements.txt` 或 `pyproject.toml` 记录依赖
- 使用上下文管理器处理资源(如文件操作)
- 优先使用列表推导式、生成器表达式和字典推导式
- 使用 `pytest` 进行测试,保持高测试覆盖率
- 使用文档字符串docstrings记录函数、类和模块
- 遵循面向对象设计原则SOLID
- 使用异常处理保证程序健壮性
- 使用 `dataclasses` 或 `pydantic` 模型表示数据