Use TypeAlias where possible for type aliases (#7630)

This commit is contained in:
Alex Waygood
2022-04-16 02:01:00 +01:00
committed by GitHub
parent c0e6dd3f3f
commit 740193a8fc
218 changed files with 760 additions and 625 deletions

View File

@@ -1,7 +1,8 @@
from collections.abc import MutableMapping
from typing import Any
from typing_extensions import TypeAlias
_Attrs = MutableMapping[Any, str]
_Attrs: TypeAlias = MutableMapping[Any, str]
def nofollow(attrs: _Attrs, new: bool = ...) -> _Attrs: ...
def target_blank(attrs: _Attrs, new: bool = ...) -> _Attrs: ...

View File

@@ -1,9 +1,10 @@
from collections.abc import Container, Iterable, MutableMapping
from typing import Any, Pattern, Protocol
from typing_extensions import TypeAlias
from .html5lib_shim import Filter
_Attrs = MutableMapping[Any, str]
_Attrs: TypeAlias = MutableMapping[Any, str]
class _Callback(Protocol):
def __call__(self, attrs: _Attrs, new: bool = ...) -> _Attrs: ...

View File

@@ -1,5 +1,6 @@
from collections.abc import Callable, Container, Iterable
from typing import Any, Pattern
from typing_extensions import TypeAlias
from .css_sanitizer import CSSSanitizer
from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter
@@ -38,9 +39,9 @@ class Cleaner:
) -> None: ...
def clean(self, text: str) -> str: ...
_AttributeFilter = Callable[[str, str, str], bool]
_AttributeDict = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter]
_Attributes = _AttributeFilter | _AttributeDict | list[str]
_AttributeFilter: TypeAlias = Callable[[str, str, str], bool]
_AttributeDict: TypeAlias = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter]
_Attributes: TypeAlias = _AttributeFilter | _AttributeDict | list[str]
def attribute_filter_factory(attributes: _Attributes) -> _AttributeFilter: ...