From 3bc3f7afbfdb7decf0a0460b600edfabb35c5056 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 19 Jun 2026 14:18:30 +0100 Subject: [PATCH] Add stub for `html._replace_charref` from standard library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `_replace_charref` is defined here: https://github.com/python/cpython/blob/64fab74bd7288bfa67cd7727452febdaafed4270/Lib/html/__init__.py#L91-L115 Although it’s a private attribute we have a use case for importing it: We re-implement `html.unescape` using our own definition of `_charref`, but we don’t want to reimpliment `_replace_charref`. Example can be found [in our codebase](https://github.com/alphagov/notifications-utils/blob/1eccc101a96cf120ce7bdc71528222ebc694432b/notifications_utils/formatters.py#L161-L167). --- stdlib/html/__init__.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/html/__init__.pyi b/stdlib/html/__init__.pyi index 8ad72f126588..71e971d15044 100644 --- a/stdlib/html/__init__.pyi +++ b/stdlib/html/__init__.pyi @@ -1,4 +1,7 @@ +import re + __all__ = ["escape", "unescape"] def escape(s: str, quote: bool = True) -> str: ... def unescape(s: str) -> str: ... +def _replace_charref(s: re.Match[str]) -> str: ...