From 4fcff943d047e1707f76e0fb60ff233987a84cfb Mon Sep 17 00:00:00 2001 From: qwist1233-cpu Date: Fri, 6 Nov 2026 11:43:41 +0300 Subject: [PATCH 1/2] [Markdown] Add toc.unique's counters parameter and DelimiterProcessor.rule_of_3 Markdown 3.11.3 gave `unique()` an optional `counters` cache and `DelimiterProcessor` a static `rule_of_3()`; neither is in the stubs, so today's daily stubtest run reported both. Verified against the installed package: `inspect.signature(toc.unique)` is `(id: str, ids: MutableSet[str], counters: dict[str, int] | None = None) -> str`, and `rule_of_3` is a `staticmethod` with `(opener: int, closer: int) -> bool`. stubtest reproduces the two errors from the issue without this change and is clean with it; `tests/mypy_test.py stubs/Markdown` passes on 3.10-3.13. Closes #16709 --- stubs/Markdown/markdown/extensions/toc.pyi | 2 +- stubs/Markdown/markdown/inlinepatterns.pyi | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/stubs/Markdown/markdown/extensions/toc.pyi b/stubs/Markdown/markdown/extensions/toc.pyi index 27fd77b833ff..aa55cca22612 100644 --- a/stubs/Markdown/markdown/extensions/toc.pyi +++ b/stubs/Markdown/markdown/extensions/toc.pyi @@ -22,7 +22,7 @@ class _TocToken(_FlatTocToken): def slugify(value: str, separator: str, unicode: bool = False) -> str: ... def slugify_unicode(value: str, separator: str) -> str: ... -def unique(id: str, ids: MutableSet[str]) -> str: ... +def unique(id: str, ids: MutableSet[str], counters: dict[str, int] | None = None) -> str: ... @deprecated("Use `render_inner_html` and `striptags` instead.") def get_name(el: Element) -> str: ... @deprecated("Use `run_postprocessors`, `render_inner_html` and/or `striptags` instead.") diff --git a/stubs/Markdown/markdown/inlinepatterns.pyi b/stubs/Markdown/markdown/inlinepatterns.pyi index 7f5ac1711cb1..6c7060030e2b 100644 --- a/stubs/Markdown/markdown/inlinepatterns.pyi +++ b/stubs/Markdown/markdown/inlinepatterns.pyi @@ -111,6 +111,8 @@ class DelimiterProcessor(InlineProcessor): def reset(self) -> None: ... def increment_next_position(self, start: int, count: int) -> None: ... def get_cached_result(self, pos: int, data: str) -> tuple[Element, int, int]: ... + @staticmethod + def rule_of_3(opener: int, closer: int) -> bool: ... def get_match(self, data: str, start: int) -> re.Match[str] | None: ... def search(self, data: str, start: int) -> re.Match[str] | None: ... def add_region(self, delim: Delimiter, a: int, b: int, c: int, d: int, size: int) -> None: ... From a6ea62b2c61d806324bcf5fc27a21db12fcaa31b Mon Sep 17 00:00:00 2001 From: qwist1233-cpu Date: Sat, 7 Nov 2026 11:13:03 +0300 Subject: [PATCH 2/2] [Markdown] Use a protocol for toc.unique's counters, bump version Review feedback: `dict[str, int]` is narrower than the runtime needs. `unique()` only calls `counters.get(base, 0)` and assigns `counters[base] = count`, so a two-method protocol covers it. Also bump METADATA.toml to ~=3.11.3, the release that added both `counters` and `DelimiterProcessor.rule_of_3`. Co-Authored-By: Claude Opus 5 --- stubs/Markdown/METADATA.toml | 2 +- stubs/Markdown/markdown/extensions/toc.pyi | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/stubs/Markdown/METADATA.toml b/stubs/Markdown/METADATA.toml index 082b7e378938..c68111021308 100644 --- a/stubs/Markdown/METADATA.toml +++ b/stubs/Markdown/METADATA.toml @@ -1,2 +1,2 @@ -version = "~=3.11.2" +version = "~=3.11.3" upstream-repository = "https://github.com/Python-Markdown/markdown" diff --git a/stubs/Markdown/markdown/extensions/toc.pyi b/stubs/Markdown/markdown/extensions/toc.pyi index aa55cca22612..f7adf9c3f74d 100644 --- a/stubs/Markdown/markdown/extensions/toc.pyi +++ b/stubs/Markdown/markdown/extensions/toc.pyi @@ -1,6 +1,6 @@ from collections.abc import Iterator, MutableSet from re import Pattern -from typing import Any, TypedDict, type_check_only +from typing import Any, Protocol, TypedDict, type_check_only from typing_extensions import deprecated from xml.etree.ElementTree import Element @@ -20,9 +20,14 @@ class _FlatTocToken(TypedDict): class _TocToken(_FlatTocToken): children: list[_TocToken] +@type_check_only +class _IdCounters(Protocol): + def get(self, key: str, default: int, /) -> int: ... + def __setitem__(self, key: str, value: int, /) -> None: ... + def slugify(value: str, separator: str, unicode: bool = False) -> str: ... def slugify_unicode(value: str, separator: str) -> str: ... -def unique(id: str, ids: MutableSet[str], counters: dict[str, int] | None = None) -> str: ... +def unique(id: str, ids: MutableSet[str], counters: _IdCounters | None = None) -> str: ... @deprecated("Use `render_inner_html` and `striptags` instead.") def get_name(el: Element) -> str: ... @deprecated("Use `run_postprocessors`, `render_inner_html` and/or `striptags` instead.")