Ruff v0.16.0

Simon Willison's Blog 工具

摘要

Ruff v0.16.0 大幅扩展了默认规则覆盖范围,从 59 条增加到 413 条,能够捕获更多严重问题,如语法错误和运行时错误。此次更新可能会破坏现有的 CI 工作流程,但提供了自动修复功能,使用 `--fix --unsafe-fixes` 选项。

暂无内容
查看原文
查看缓存全文

缓存时间: 2026/07/27 01:37

# Ruff v0.16.0 来源:https://simonwillison.net/2026/Jul/25/ruff/ **Ruff v0.16.0 (https://astral.sh/blog/ruff-v0.16.0)**。Astral 在7月23日发布了其 Python 代码检查工具 Ruff 的一个重要新版本。我今天注意到是因为我的各种 CI 作业都开始失败,原因是新的默认 Ruff 检查以及我未固定版本的 `"ruff"` 开发依赖。 摘自 Brent Westbrook 的发布公告: > Ruff 现在默认启用 413 条规则,而之前版本是 59 条。自 v0.1.0 (https://github.com/astral-sh/ruff/blob/main/changelogs/0.1.x.md#breaking-changes) 上次修改默认规则集以来,Ruff 的规则总数已从 708 增长到 968。许多规则能捕获严重问题,包括语法错误 (https://docs.astral.sh/ruff/rules/load-before-global-declaration) 和立即运行时错误 (https://docs.astral.sh/ruff/rules/yield-in-init/),但之前并未默认启用。借助新的规则集,Ruff 无需任何配置就能让你注意到这些问题以及许多其他问题。 下面是一个一行命令,可以在任何 Python 项目上尝试: `` uvx ruff@latest check . `` 我在自己最大的三个项目——Datasette (https://datasette.io/)、sqlite-utils (https://sqlite-utils.datasette.io/) 和 LLM (https://llm.datasette.io/)——上运行了最新的 Ruff,结果发现了 *数百个* 触犯新默认规则的小问题。 这三个项目都有非常全面的测试套件,在 CI 中针对 Python 3.10 到 Python 3.14 执行,因此这样的升级相当安全。以下命令完成了大部分升级工作: `` uvx ruff@latest check . --fix --unsafe-fixes `` 针对 `sqlite-utils`,该命令报告: `` Found 1618 errors (1538 fixed, 80 remaining). `` 作为一个示例,下面是剩余的其中三个问题。Ruff 对每个问题都做了很好的解释: `` DTZ005 `datetime.datetime.now()` called without a `tz` argument --> tests/test_duplicate.py:17:10 | 15 | "datetime_col" TEXT)""") 16 | # Insert one row of mock data: 17 | dt = datetime.datetime.now() | ^^^^^^^^^^^^^^^^^^^^^^^ 18 | data = { 19 | "text_col": "Cleo", | help: Pass a `datetime.timezone` object to the `tz` parameter BLE001 Do not catch blind exception: `Exception` --> tests/test_plugins.py:16:12 | 14 | db.execute("select * from pragma_function_list()") 15 | return True 16 | except Exception: | ^^^^^^^^^ 17 | return False 18 | finally: | B018 Found useless attribute access. Either assign it to a variable or remove it. --> tests/test_update.py:46:5 | 44 | def test_update_invalid_pk(fresh_db, pk, update_pk): 45 | table = fresh_db["table"] 46 | table.insert({"id1": 5, "id2": 3, "v": 1}, pk=pk).last_pk | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 47 | with pytest.raises(NotFoundError): 48 | table.update(update_pk, {"v": 2}) | `` 毫不奇怪,考虑到 Astral 的新家 OpenAI (https://simonwillison.net/2026/Mar/19/openai-acquiring-astral/),这个输出提供了编程代理修复问题所需的一切信息。 我使用 Codex (GPT-5.6 Sol high) 升级了 LLM (https://github.com/simonw/llm/pull/1557) 和 sqlite-utils (https://github.com/simonw/sqlite-utils/pull/814),使用 Claude Code (搭配 Opus 5) 升级了 Datasette (https://github.com/simonw/datasette/pull/2857)。

相似文章

Rust 1.97.0 发布公告

Lobsters Hottest

Rust 1.97.0 已发布,默认启用符号修饰 v0,Cargo 支持禁止警告,并且链接器输出不再隐藏。

Racket v9.2

Lobsters Hottest

Racket v9.2 发布,改进包括更安全的模式匹配检查、Typed Racket 修复、Unicode 17.0 支持,以及许多其他修复和文档更新。