Skip to content

Commit a6ea62b

Browse files
qwist1233-cpuclaude
andcommitted
[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 <noreply@anthropic.com>
1 parent 4fcff94 commit a6ea62b

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎stubs/Markdown/METADATA.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = "~=3.11.2"
1+
version = "~=3.11.3"
22
upstream-repository = "https://github.com/Python-Markdown/markdown"

‎stubs/Markdown/markdown/extensions/toc.pyi‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Iterator, MutableSet
22
from re import Pattern
3-
from typing import Any, TypedDict, type_check_only
3+
from typing import Any, Protocol, TypedDict, type_check_only
44
from typing_extensions import deprecated
55
from xml.etree.ElementTree import Element
66

@@ -20,9 +20,14 @@ class _FlatTocToken(TypedDict):
2020
class _TocToken(_FlatTocToken):
2121
children: list[_TocToken]
2222

23+
@type_check_only
24+
class _IdCounters(Protocol):
25+
def get(self, key: str, default: int, /) -> int: ...
26+
def __setitem__(self, key: str, value: int, /) -> None: ...
27+
2328
def slugify(value: str, separator: str, unicode: bool = False) -> str: ...
2429
def slugify_unicode(value: str, separator: str) -> str: ...
25-
def unique(id: str, ids: MutableSet[str], counters: dict[str, int] | None = None) -> str: ...
30+
def unique(id: str, ids: MutableSet[str], counters: _IdCounters | None = None) -> str: ...
2631
@deprecated("Use `render_inner_html` and `striptags` instead.")
2732
def get_name(el: Element) -> str: ...
2833
@deprecated("Use `run_postprocessors`, `render_inner_html` and/or `striptags` instead.")

0 commit comments

Comments
 (0)