Description
#13969 introduced a small regression by changing the definition of _Filter
. As far as I can tell it's legal to pass html5lib filters to a bleach Cleaner
, but those filters won't conform to the _Filter
protocol, since they're not an instance of BleachSanitizerFilter
, they're an instance of the html5lib base class Filter
instead. That's fine for the source
argument, since it's contravariant, but it's not fine for the return type which is covariant, so it won't allow a superclass.
Small example:
filters: list[_Filter] = [WhitespaceFilter] # this will now cause an error
Similarly you now can't pass bleach's own LinkifyFilter
to Cleaner
, since it derives from Filter
not BleachSanitizerFilter
.
So I suggest changing the definition of _Filter
to:
def __call__(self, *, source: BleachSanitizerFilter) -> SanitizerFilter: ...
Although it technically seems more safe and correct to make it:
def __call__(self, *, source: SanitizerFilter) -> SanitizerFilter: ...
But this might cause churn for custom filters people already defined. The source type has been too narrow for a while.