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,11 +1,12 @@
from typing import Callable, Generator, Pattern, TypeVar
from typing_extensions import TypeAlias
from xml.etree.ElementTree import Element
xpath_tokenizer_re: Pattern[str]
_token = tuple[str, str]
_next = Callable[[], _token]
_callback = Callable[[_SelectorContext, list[Element]], Generator[Element, None, None]]
_token: TypeAlias = tuple[str, str]
_next: TypeAlias = Callable[[], _token]
_callback: TypeAlias = Callable[[_SelectorContext, list[Element]], Generator[Element, None, None]]
def xpath_tokenizer(pattern: str, namespaces: dict[str, str] | None = ...) -> Generator[_token, None, None]: ...
def get_parent_map(context: _SelectorContext) -> dict[Element, Element]: ...

View File

@@ -14,7 +14,7 @@ from typing import (
TypeVar,
overload,
)
from typing_extensions import Literal, SupportsIndex, TypeGuard
from typing_extensions import Literal, SupportsIndex, TypeAlias, TypeGuard
if sys.version_info >= (3, 9):
__all__ = [
@@ -101,9 +101,9 @@ else:
]
_T = TypeVar("_T")
_FileRead = StrOrBytesPath | FileDescriptor | SupportsRead[bytes] | SupportsRead[str]
_FileWriteC14N = StrOrBytesPath | FileDescriptor | SupportsWrite[bytes]
_FileWrite = _FileWriteC14N | SupportsWrite[str]
_FileRead: TypeAlias = StrOrBytesPath | FileDescriptor | SupportsRead[bytes] | SupportsRead[str]
_FileWriteC14N: TypeAlias = StrOrBytesPath | FileDescriptor | SupportsWrite[bytes]
_FileWrite: TypeAlias = _FileWriteC14N | SupportsWrite[str]
VERSION: str
@@ -352,7 +352,7 @@ def fromstringlist(sequence: Sequence[str | bytes], parser: XMLParser | None = .
# TreeBuilder is called by client code (they could pass strs, bytes or whatever);
# but we don't want to use a too-broad type, or it would be too hard to write
# elementfactories.
_ElementFactory = Callable[[Any, dict[Any, Any]], Element]
_ElementFactory: TypeAlias = Callable[[Any, dict[Any, Any]], Element]
class TreeBuilder:
if sys.version_info >= (3, 8):