Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Regression in bleach stubs #14040

Copy link
Copy link
Closed
@Daverball

Description

@Daverball
Issue body actions

#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.