Repository navigation
[Markdown] Add toc.unique's counters parameter and DelimiterProcessor.rule_of_3 - #16713
Conversation
….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 python#16709
This comment has been minimized.
This comment has been minimized.
srittau
left a comment
There was a problem hiding this comment.
This also needs a version bump.
| 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: ... |
There was a problem hiding this comment.
dict is too narrow. This should use a protocol for the two methods that are actually used.
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>
|
Thanks — both done in a6ea62b. Protocol. @type_check_only
class _IdCounters(Protocol):
def get(self, key: str, default: int, /) -> int: ...
def __setitem__(self, key: str, value: int, /) -> None: ...Positional-only, so Version bump.
|
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Both stubtest errors from today's daily run (#16709), which were the only failures in it.
Markdown 3.11.3 added an optional
counterscache totoc.unique()and a staticrule_of_3()toDelimiterProcessor; the stubs have neither.Verified against the installed package rather than from the diff:
rule_of_3goes betweenget_cached_resultandget_match, where it sits at runtime.Success: no issues found in 33 modules.tests/mypy_test.py stubs/Markdown— success, 198 files checked (3.10-3.13).Closes #16709