Use PEP 585 syntax wherever possible (#6717)

This commit is contained in:
Alex Waygood
2021-12-28 10:31:43 +00:00
committed by GitHub
parent e6cb341d94
commit 8d5d2520ac
237 changed files with 966 additions and 1069 deletions

View File

@@ -1,14 +1,14 @@
from typing import Any, Iterable, List, Tuple, Type, TypeVar
from typing import Any, Iterable, Type, TypeVar
_T = TypeVar("_T")
StringTypes: tuple[Type[str]]
class NodeList(List[_T]):
class NodeList(list[_T]):
length: int
def item(self, index: int) -> _T | None: ...
class EmptyNodeList(Tuple[Any, ...]):
class EmptyNodeList(tuple[Any, ...]):
length: int
def item(self, index: int) -> None: ...
def __add__(self, other: Iterable[_T]) -> NodeList[_T]: ... # type: ignore[override]

View File

@@ -1,5 +1,5 @@
import sys
from typing import IO, Any, Sequence, Tuple, Union
from typing import IO, Any, Sequence, Union
from typing_extensions import Literal
from xml.dom.minidom import Document, DOMImplementation, Element, Text
from xml.sax.handler import ContentHandler
@@ -17,7 +17,7 @@ CHARACTERS: Literal["CHARACTERS"]
_DocumentFactory = Union[DOMImplementation, None]
_Node = Union[Document, Element, Text]
_Event = Tuple[
_Event = tuple[
Literal[
Literal["START_ELEMENT"],
Literal["END_ELEMENT"],

View File

@@ -1,11 +1,11 @@
from typing import Callable, Generator, List, Pattern, Tuple, TypeVar
from typing import Callable, Generator, Pattern, TypeVar
from xml.etree.ElementTree import Element
xpath_tokenizer_re: Pattern[str]
_token = Tuple[str, str]
_token = tuple[str, str]
_next = Callable[[], _token]
_callback = Callable[[_SelectorContext, List[Element]], Generator[Element, None, None]]
_callback = 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

@@ -4,7 +4,6 @@ from typing import (
IO,
Any,
Callable,
Dict,
Generator,
ItemsView,
Iterable,
@@ -257,7 +256,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 = Callable[[Any, dict[Any, Any]], Element]
class TreeBuilder:
if sys.version_info >= (3, 8):