dj-lint
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLint and Type-Check
代码检查与类型检查
Run the full static-analysis suite on the project and fix any issues found.
- — lint the code
uv run ruff check src - — verify formatting
uv run ruff format --check src - — static type analysis
uv run pyrefly check src
Fix every issue reported (re-run until clean) and report a short summary of what changed when done. If a failure is not auto-fixable, explain what needs human judgement rather than silencing it.
对项目运行完整的静态分析套件,并修复发现的所有问题。
- — 检查代码
uv run ruff check src - — 验证代码格式
uv run ruff format --check src - — 静态类型分析
uv run pyrefly check src
修复所有报告的问题(重复运行直到无问题),完成后提交一份简短的修改总结。如果某个问题无法自动修复,请说明需要人工判断的内容,而非直接忽略。
Pyrefly + Django gotchas
Pyrefly + Django 注意事项
Pyrefly has built-in Django support (via ), but a few things aren't covered yet. Recognize these before reaching for :
django-stubs# type: ignore- Reverse relations (,
user.order_set) are not supported. This is a known pyrefly limitation, not a real bug. The right fix is to query the child model directly from its repository (author.article_set) — push the access down into the repo layer rather than suppressing it. Only if that's impossible, narrow it withOrderRepository().list_for_user(user_id)at a single call site.# type: ignore[attr-defined] - is generic over
ManyRelatedManager, not the concrete child. Don't rely on pyrefly to catch a mistyped M2M target — cover it with a test instead.[Parent, Model] - Chained QuerySet methods beyond are thinly typed. Keep chains inside the repository where the return type is an annotated
.all(); don't let querysets leak out into services.list[SomeDTO]
See pyrefly.org/en/docs/django for the current support matrix. Pyrefly's Django support is actively evolving — re-check when upgrading.
Pyrefly 内置了Django支持(通过),但仍有部分内容未覆盖。在使用之前,请先注意以下几点:
django-stubs# type: ignore- 反向关联(、
user.order_set)不受支持。 这是Pyrefly的已知限制,并非真正的Bug。正确的修复方式是直接从子模型的仓库中查询(author.article_set)—— 将访问逻辑下移到仓库层,而非忽略该问题。只有在无法实现的情况下,才在单个调用位置使用OrderRepository().list_for_user(user_id)来限定。# type: ignore[attr-defined] - 是基于
ManyRelatedManager的泛型类,而非具体的子模型。不要依赖Pyrefly来捕获多对多(M2M)目标的类型错误——改用测试来覆盖这类场景。[Parent, Model] - 之外的链式QuerySet方法类型定义较弱。 请将链式调用放在仓库层中,确保返回类型是带有注解的
.all();不要让QuerySet渗透到服务层中。list[SomeDTO]
查看pyrefly.org/en/docs/django获取当前支持矩阵。Pyrefly的Django支持正在持续演进——升级时请重新检查。