From 2f9bd2471656650e17c73f5f1e9de996a9b65b83 Mon Sep 17 00:00:00 2001 From: David Salvisberg Date: Tue, 13 May 2025 12:23:36 +0200 Subject: [PATCH] Fix regression in definition of `bleach.sanitizer._Filter` (#14041) --- stubs/bleach/bleach/sanitizer.pyi | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/stubs/bleach/bleach/sanitizer.pyi b/stubs/bleach/bleach/sanitizer.pyi index f13e86378..a86be65fe 100644 --- a/stubs/bleach/bleach/sanitizer.pyi +++ b/stubs/bleach/bleach/sanitizer.pyi @@ -1,6 +1,6 @@ from collections.abc import Callable, Container, Iterable, Iterator from re import Pattern -from typing import Final, Protocol +from typing import Final, Protocol, type_check_only from typing_extensions import TypeAlias from html5lib.filters.base import Filter @@ -22,9 +22,13 @@ INVISIBLE_REPLACEMENT_CHAR: Final = "?" class NoCssSanitizerWarning(UserWarning): ... -# A html5lib Filter class -class _Filter(Protocol): - def __call__(self, *, source: BleachSanitizerFilter) -> BleachSanitizerFilter: ... +@type_check_only +class _FilterConstructor(Protocol): + def __call__(self, *, source: BleachSanitizerFilter) -> Filter: ... + +# _FilterConstructor used to be called _Filter +# this alias is obsolete and can potentially be removed in the future +_Filter: TypeAlias = _FilterConstructor # noqa: Y047 _AttributeFilter: TypeAlias = Callable[[str, str, str], bool] _AttributeDict: TypeAlias = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter] @@ -48,7 +52,7 @@ class Cleaner: protocols: Iterable[str] = ..., strip: bool = False, strip_comments: bool = True, - filters: Iterable[_Filter] | None = None, + filters: Iterable[_FilterConstructor] | None = None, css_sanitizer: CSSSanitizer | None = None, ) -> None: ... def clean(self, text: str) -> str: ...