dj-lint

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Lint and Type-Check

代码检查与类型检查

Run the full static-analysis suite on the project and fix any issues found.
  1. uv run ruff check src
    — lint the code
  2. uv run ruff format --check src
    — verify formatting
  3. uv run pyrefly check src
    — static type analysis
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.
对项目运行完整的静态分析套件,并修复发现的所有问题。
  1. uv run ruff check src
    — 检查代码
  2. uv run ruff format --check src
    — 验证代码格式
  3. uv run pyrefly check src
    — 静态类型分析
修复所有报告的问题(重复运行直到无问题),完成后提交一份简短的修改总结。如果某个问题无法自动修复,请说明需要人工判断的内容,而非直接忽略。

Pyrefly + Django gotchas

Pyrefly + Django 注意事项

Pyrefly has built-in Django support (via
django-stubs
), but a few things aren't covered yet. Recognize these before reaching for
# type: ignore
:
  • Reverse relations (
    user.order_set
    ,
    author.article_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 (
    OrderRepository().list_for_user(user_id)
    ) — push the access down into the repo layer rather than suppressing it. Only if that's impossible, narrow it with
    # type: ignore[attr-defined]
    at a single call site.
  • ManyRelatedManager
    is generic over
    [Parent, Model]
    , not the concrete child. Don't rely on pyrefly to catch a mistyped M2M target — cover it with a test instead.
  • Chained QuerySet methods beyond
    .all()
    are thinly typed.
    Keep chains inside the repository where the return type is an annotated
    list[SomeDTO]
    ; don't let querysets leak out into services.
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
    author.article_set
    )不受支持。
    这是Pyrefly的已知限制,并非真正的Bug。正确的修复方式是直接从子模型的仓库中查询(
    OrderRepository().list_for_user(user_id)
    )—— 将访问逻辑下移到仓库层,而非忽略该问题。只有在无法实现的情况下,才在单个调用位置使用
    # type: ignore[attr-defined]
    来限定。
  • ManyRelatedManager
    是基于
    [Parent, Model]
    的泛型类
    ,而非具体的子模型。不要依赖Pyrefly来捕获多对多(M2M)目标的类型错误——改用测试来覆盖这类场景。
  • .all()
    之外的链式QuerySet方法类型定义较弱。
    请将链式调用放在仓库层中,确保返回类型是带有注解的
    list[SomeDTO]
    ;不要让QuerySet渗透到服务层中。
查看pyrefly.org/en/docs/django获取当前支持矩阵。Pyrefly的Django支持正在持续演进——升级时请重新检查。