馃敡 Update pre-commit hooks (ruff 0.16.6, mypy 2.3.1) - #424
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A fresh
pre-commit autoupdateon current master, replacing #396 (the bot's May branch), whose CI was red because the ruff autofix had inserted an unguardedfrom typing_extensions import Selfintomarkdown_it/tree.pywhiletyping_extensionsis not a runtime dependency.astral-sh/ruff-pre-commitpre-commit/mirrors-mypypre-commit/pre-commit-hooksTwo 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: _NodeTypepattern inSyntaxTreeNodetoSelf, importing it fromtyping_extensions. That import is now underif TYPE_CHECKING:(the module already hasfrom __future__ import annotations, and every use ofSelfis annotation-only). Verified by importingmarkdown_it.treeand callingSyntaxTreeNode(...).pretty()withtyping_extensionsblocked via a meta-path finder. Nothing was added todependencies.Manual lint fixes (all from ruff 0.16's expanded default rule set, none from rules this repo selects):
EXE001: removed the vestigial shebang frommarkdown_it/cli/parse.py(the CLI ships via the console script;python -m markdown_it.cli.parsestill works).PIE810:k.startswith(("render", "_"))inrenderer.py.PYI045:OptionsDict.__iter__now declaresIterator[str](it always returned one), dropping atype: ignore.PYI034:__new__in a test helper annotated withSelf.RUF036/UP045:None | Xunions reordered toX | None. Type-equivalent.type: ignore[import-untyped]removed.Autofix changes worth knowing about (all type-equivalent or comment-only):
Token.attrSet(value: str | int | float)now readsstr | float(PYI041). Under PEP 484's numeric towerfloatalready acceptsint, so nothing changes for callers, but rendered signatures will look narrower.# noqa: E731comments infence.pyremoved by RUF100: ruff 0.16 no longer flags those lambdas, so the comments were dead, and the hook auto-removes them if restored.README.md,AGENTS.md,CHANGELOG.mdanddocs/. All are formatting-only inside fenced examples (quotes, wrapping,...stubs); no prose changed.For the maintainers to decide (not changed here)
With
pyproject.tomluntouched, 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 explicitselectso future ruff releases don't silently change what's enforced.Verification
pre-commit run --all-files: every hook passes under the new pins.import markdown_it, markdown_it.tree, markdown_it.cli.parsesucceeds withtyping_extensionsunavailable.Supersedes #396.