From bc204cde1f0f2962e142631d15fa19df3ca69642 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2026 16:38:21 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.15.12 → v0.16.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.15.12...v0.16.0) - [github.com/pre-commit/mirrors-mypy: v1.20.2 → v2.3.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.20.2...v2.3.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 04230b02..5017c7d9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,14 +24,14 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.12 + rev: v0.16.0 hooks: - id: ruff args: [--fix] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.20.2 + rev: v2.3.0 hooks: - id: mypy additional_dependencies: [mdurl, typing-extensions] From 75d1f7984320641ba6c09ea32865ecd40f4248b1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2026 16:38:40 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- markdown_it/common/utils.py | 2 +- markdown_it/rules_block/fence.py | 4 ++-- markdown_it/rules_core/smartquotes.py | 4 ++-- markdown_it/token.py | 4 ++-- markdown_it/tree.py | 28 +++++++++++++-------------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/markdown_it/common/utils.py b/markdown_it/common/utils.py index 11bda644..500a590d 100644 --- a/markdown_it/common/utils.py +++ b/markdown_it/common/utils.py @@ -102,7 +102,7 @@ def replaceEntityPattern(match: str, name: str) -> str: if name in entities: return entities[name] - code: None | int = None + code: int | None = None if pat := DIGITAL_ENTITY_BASE10_RE.fullmatch(name): code = int(pat.group(1), 10) elif pat := DIGITAL_ENTITY_BASE16_RE.fullmatch(name): diff --git a/markdown_it/rules_block/fence.py b/markdown_it/rules_block/fence.py index 0d7e651e..621924b5 100644 --- a/markdown_it/rules_block/fence.py +++ b/markdown_it/rules_block/fence.py @@ -37,10 +37,10 @@ def make_fence_rule( closing_matcher: Callable[[int, int], bool] if exact_match: # closing code fence must have exactly the same number of markers as the opening one - closing_matcher = lambda opening_len, closing_len: closing_len == opening_len # noqa: E731 + closing_matcher = lambda opening_len, closing_len: closing_len == opening_len else: # closing code fence must be at least as long as the opening one - closing_matcher = lambda opening_len, closing_len: closing_len >= opening_len # noqa: E731 + closing_matcher = lambda opening_len, closing_len: closing_len >= opening_len def _fence_rule( state: StateBlock, startLine: int, endLine: int, silent: bool diff --git a/markdown_it/rules_core/smartquotes.py b/markdown_it/rules_core/smartquotes.py index f9b8b457..3392dcb5 100644 --- a/markdown_it/rules_core/smartquotes.py +++ b/markdown_it/rules_core/smartquotes.py @@ -58,7 +58,7 @@ def process_inlines(tokens: list[Token], state: StateCore) -> None: # Find previous character, # default to space if it's the beginning of the line - lastChar: None | int = 0x20 + lastChar: int | None = 0x20 if t.start(0) + lastIndex - 1 >= 0: lastChar = charCodeAt(text, t.start(0) + lastIndex - 1) @@ -75,7 +75,7 @@ def process_inlines(tokens: list[Token], state: StateCore) -> None: # Find next character, # default to space if it's the end of the line - nextChar: None | int = 0x20 + nextChar: int | None = 0x20 if pos < maximum: nextChar = charCodeAt(text, pos) diff --git a/markdown_it/token.py b/markdown_it/token.py index d6d0b453..309bb96f 100644 --- a/markdown_it/token.py +++ b/markdown_it/token.py @@ -95,11 +95,11 @@ def attrPush(self, attrData: tuple[str, str | int | float]) -> None: name, value = attrData self.attrSet(name, value) - def attrSet(self, name: str, value: str | int | float) -> None: + def attrSet(self, name: str, value: str | float) -> None: """Set `name` attribute to `value`. Override old value if exists.""" self.attrs[name] = value - def attrGet(self, name: str) -> None | str | int | float: + def attrGet(self, name: str) -> str | int | float | None: """Get the value of attribute `name`, or null if it does not exist.""" return self.attrs.get(name, None) diff --git a/markdown_it/tree.py b/markdown_it/tree.py index 24bc2466..b78fd5d5 100644 --- a/markdown_it/tree.py +++ b/markdown_it/tree.py @@ -9,6 +9,8 @@ import textwrap from typing import Any, NamedTuple, TypeVar, overload +from typing_extensions import Self + from .token import Token @@ -84,13 +86,13 @@ def __getitem__(self: _NodeType, item: int) -> _NodeType: ... @overload def __getitem__(self: _NodeType, item: slice) -> list[_NodeType]: ... - def __getitem__(self: _NodeType, item: int | slice) -> _NodeType | list[_NodeType]: + def __getitem__(self, item: int | slice) -> Self | list[Self]: return self.children[item] - def to_tokens(self: _NodeType) -> list[Token]: + def to_tokens(self) -> list[Token]: """Recover the linear token stream.""" - def recursive_collect_tokens(node: _NodeType, token_list: list[Token]) -> None: + def recursive_collect_tokens(node: Self, token_list: list[Token]) -> None: if node.type == "root": for child in node.children: recursive_collect_tokens(child, token_list) @@ -108,19 +110,19 @@ def recursive_collect_tokens(node: _NodeType, token_list: list[Token]) -> None: return tokens @property - def children(self: _NodeType) -> list[_NodeType]: + def children(self) -> list[Self]: return self._children @children.setter - def children(self: _NodeType, value: list[_NodeType]) -> None: + def children(self, value: list[Self]) -> None: self._children = value @property - def parent(self: _NodeType) -> _NodeType | None: + def parent(self) -> Self | None: return self._parent # type: ignore @parent.setter - def parent(self: _NodeType, value: _NodeType | None) -> None: + def parent(self, value: Self | None) -> None: self._parent = value @property @@ -139,7 +141,7 @@ def is_nested(self) -> bool: return bool(self.nester_tokens) @property - def siblings(self: _NodeType) -> Sequence[_NodeType]: + def siblings(self) -> Sequence[Self]: """Get siblings of the node. Gets the whole group of siblings, including self. @@ -165,7 +167,7 @@ def type(self) -> str: return self.nester_tokens.opening.type.removesuffix("_open") @property - def next_sibling(self: _NodeType) -> _NodeType | None: + def next_sibling(self) -> Self | None: """Get the next node in the sequence of siblings. Returns `None` if this is the last sibling. @@ -176,7 +178,7 @@ def next_sibling(self: _NodeType) -> _NodeType | None: return None @property - def previous_sibling(self: _NodeType) -> _NodeType | None: + def previous_sibling(self) -> Self | None: """Get the previous node in the sequence of siblings. Returns `None` if this is the first sibling. @@ -241,9 +243,7 @@ def pretty( ) return text - def walk( - self: _NodeType, *, include_self: bool = True - ) -> Generator[_NodeType, None, None]: + def walk(self, *, include_self: bool = True) -> Generator[Self, None, None]: """Recursively yield all descendant nodes in the tree starting at self. The order mimics the order of the underlying linear token @@ -282,7 +282,7 @@ def attrs(self) -> dict[str, str | int | float]: """Html attributes.""" return self._attribute_token().attrs - def attrGet(self, name: str) -> None | str | int | float: + def attrGet(self, name: str) -> str | int | float | None: """Get the value of attribute `name`, or null if it does not exist.""" return self._attribute_token().attrGet(name)