Skip to content

馃敡 Update pre-commit hooks (ruff 0.16.6, mypy 2.3.1) - #424

Merged
chrisjsewell merged 3 commits into
masterfrom
claude/pre-commit-autoupdate
Sep 9, 2026
Merged

馃敡 Update pre-commit hooks (ruff 0.16.6, mypy 2.3.1)#424
chrisjsewell merged 3 commits into
masterfrom
claude/pre-commit-autoupdate

Conversation

@chrisjsewell

@chrisjsewell chrisjsewell commented Sep 9, 2026

Copy link
Copy Markdown
Member

Summary

A fresh pre-commit autoupdate on current master, replacing #396 (the bot's May branch), whose CI was red because the ruff autofix had inserted an unguarded from typing_extensions import Self into markdown_it/tree.py while typing_extensions is not a runtime dependency.

hook before after
astral-sh/ruff-pre-commit v0.15.12 v0.16.6
pre-commit/mirrors-mypy v1.20.2 v2.3.1
pre-commit/pre-commit-hooks v6.0.0 v6.0.0 (unchanged)

Two commits: the hook bump plus the hooks' own auto-fixes, then the manual fixes for what remained. The first commit alone is not runtime-safe (see below), so squash-merge is the right choice here.

What changed and why

Runtime-safety fix. ruff's PYI019 autofix rewrites the self: _NodeType pattern in SyntaxTreeNode to Self, importing it from typing_extensions. That import is now under if TYPE_CHECKING: (the module already has from __future__ import annotations, and every use of Self is annotation-only). Verified by importing markdown_it.tree and calling SyntaxTreeNode(...).pretty() with typing_extensions blocked via a meta-path finder. Nothing was added to dependencies.

Manual lint fixes (all from ruff 0.16's expanded default rule set, none from rules this repo selects):

  • EXE001: removed the vestigial shebang from markdown_it/cli/parse.py (the CLI ships via the console script; python -m markdown_it.cli.parse still works).
  • PIE810: k.startswith(("render", "_")) in renderer.py.
  • PYI045: OptionsDict.__iter__ now declares Iterator[str] (it always returned one), dropping a type: ignore.
  • PYI034: __new__ in a test helper annotated with Self.
  • RUF036/UP045: None | X unions reordered to X | None. Type-equivalent.
  • mypy 2.3: one now-unused type: ignore[import-untyped] removed.

Autofix changes worth knowing about (all type-equivalent or comment-only):

  • Token.attrSet(value: str | int | float) now reads str | float (PYI041). Under PEP 484's numeric tower float already accepts int, so nothing changes for callers, but rendered signatures will look narrower.
  • Two # noqa: E731 comments in fence.py removed by RUF100: ruff 0.16 no longer flags those lambdas, so the comments were dead, and the hook auto-removes them if restored.
  • ruff-format 0.16 now formats Python code inside Markdown fences, hence the diffs in README.md, AGENTS.md, CHANGELOG.md and docs/. All are formatting-only inside fenced examples (quotes, wrapping, ... stubs); no prose changed.

For the maintainers to decide (not changed here)

With pyproject.toml untouched, ruff 0.16.6 enables 463 rules versus 253 under 0.15.12: the defaults grew substantially (EXE, PIE, PYI, UP007/UP045 and more are now on without being selected). It may be worth pinning an explicit select so future ruff releases don't silently change what's enforced.

Verification

  • pre-commit run --all-files: every hook passes under the new pins.
  • 993 tests pass.
  • import markdown_it, markdown_it.tree, markdown_it.cli.parse succeeds with typing_extensions unavailable.

Supersedes #396.

Run `pre-commit autoupdate` (ruff v0.15.12 -> v0.16.6, mypy v1.20.2 -> v2.3.1) and apply the fixes the updated hooks made automatically.
Findings reported by ruff v0.16.6 / mypy v2.3.1 that have no automatic fix:

- `markdown_it/tree.py`: the ruff PYI019 autofix rewrote the `_NodeType`
  self-annotations to `Self` and added an unguarded
  `from typing_extensions import Self`. `typing_extensions` is not a runtime
  dependency, so move the import under `if TYPE_CHECKING:` (every use of
  `Self` is annotation-only and the module already uses postponed
  annotations).
- `markdown_it/cli/parse.py`: EXE001, drop the shebang from a
  non-executable module (the CLI is exposed via the `markdown-it`
  console script entry point).
- `markdown_it/renderer.py`: PIE810, single `startswith` call with a tuple.
- `markdown_it/rules_block/reference.py`: RUF036, `None` last in the union.
- `markdown_it/utils.py`: PYI045, `__iter__` returns an `Iterator`; the
  `# type: ignore` it needed as an `Iterable` is no longer required.
- `tests/test_api/test_main.py`: PYI034, annotate `__new__` with `Self`.
- `tests/test_cmark_spec/get_cmark_spec.py`: drop the now unused
  `type: ignore[import-untyped]` on `import requests`.
The ruff PYI019 autofix replaced the `_NodeType` self-type pattern in
`SyntaxTreeNode` with `Self`. `_NodeType` was already in
`nitpick_ignore_regex`; `Self` was not, and it cannot resolve against the
Python 3.10 intersphinx inventory, so the Read the Docs build (which sets
`fail_on_warning`) failed on six unresolved `py:class` references.
@chrisjsewell
chrisjsewell merged commit d9b0526 into master Sep 9, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant