From 13db912e52e4df2b444738c6d2b63a51da288940 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 05:08:51 +0100 Subject: [PATCH] refactor: read the heading level without a regex mypy saw re.fullmatch() as optional. Splitting the hashes off the heading gives the same level and title. --- tests/mdsections.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/mdsections.py b/tests/mdsections.py index 893bd962e..f262a7956 100644 --- a/tests/mdsections.py +++ b/tests/mdsections.py @@ -19,7 +19,9 @@ def section(text: str, heading: str, *, stop: int | None = None) -> str: The heading is its text, or the full line with its hashes, which then fix its level; a trailing ``{ #anchor }`` is optional either way.""" - hashes, title = re.fullmatch(r"(#*)\s*(.*)", heading).groups() + title = heading.lstrip("#") + hashes = heading[: len(heading) - len(title)] + title = title.strip() start = re.search(rf"(?m)^({hashes or '#+'}) {re.escape(title)}(?:\s*\{{[^}}]*\}})?\n", text) if start is None: raise AssertionError(f"no section {heading!r}")