Use Element[Any] instead of Element in ElementTree (#14198)

This commit is contained in:
Matthew Mckee
2025-10-08 13:35:12 +01:00
committed by GitHub
parent c6b6bb7a0b
commit 12e7d4e9cf
+15 -15
View File
@@ -93,7 +93,7 @@ class Element(Generic[_Tag]):
def __init__(self, tag: _Tag, attrib: dict[str, str] = {}, **extra: str) -> None: ...
def append(self, subelement: Element[Any], /) -> None: ...
def clear(self) -> None: ...
def extend(self, elements: Iterable[Element], /) -> None: ...
def extend(self, elements: Iterable[Element[Any]], /) -> None: ...
def find(self, path: str, namespaces: dict[str, str] | None = None) -> Element | None: ...
def findall(self, path: str, namespaces: dict[str, str] | None = None) -> list[Element]: ...
@overload
@@ -104,7 +104,7 @@ class Element(Generic[_Tag]):
def get(self, key: str, default: None = None) -> str | None: ...
@overload
def get(self, key: str, default: _T) -> str | _T: ...
def insert(self, index: int, subelement: Element, /) -> None: ...
def insert(self, index: int, subelement: Element[Any], /) -> None: ...
def items(self) -> ItemsView[str, str]: ...
def iter(self, tag: str | None = None) -> Generator[Element, None, None]: ...
@overload
@@ -115,7 +115,7 @@ class Element(Generic[_Tag]):
def keys(self) -> dict_keys[str, str]: ...
# makeelement returns the type of self in Python impl, but not in C impl
def makeelement(self, tag: _OtherTag, attrib: dict[str, str], /) -> Element[_OtherTag]: ...
def remove(self, subelement: Element, /) -> None: ...
def remove(self, subelement: Element[Any], /) -> None: ...
def set(self, key: str, value: str, /) -> None: ...
def __copy__(self) -> Element[_Tag]: ... # returns the type of self in Python impl, but not in C impl
def __deepcopy__(self, memo: Any, /) -> Element: ... # Only exists in C impl
@@ -128,15 +128,15 @@ class Element(Generic[_Tag]):
# Doesn't actually exist at runtime, but instance of the class are indeed iterable due to __getitem__.
def __iter__(self) -> Iterator[Element]: ...
@overload
def __setitem__(self, key: SupportsIndex, value: Element, /) -> None: ...
def __setitem__(self, key: SupportsIndex, value: Element[Any], /) -> None: ...
@overload
def __setitem__(self, key: slice, value: Iterable[Element], /) -> None: ...
def __setitem__(self, key: slice, value: Iterable[Element[Any]], /) -> None: ...
# Doesn't really exist in earlier versions, where __len__ is called implicitly instead
@deprecated("Testing an element's truth value is deprecated.")
def __bool__(self) -> bool: ...
def SubElement(parent: Element, tag: str, attrib: dict[str, str] = ..., **extra: str) -> Element: ...
def SubElement(parent: Element[Any], tag: str, attrib: dict[str, str] = ..., **extra: str) -> Element: ...
def Comment(text: str | None = None) -> Element[_ElementCallable]: ...
def ProcessingInstruction(target: str, text: str | None = None) -> Element[_ElementCallable]: ...
@@ -155,7 +155,7 @@ class QName:
_Root = TypeVar("_Root", Element, Element | None, default=Element | None)
class ElementTree(Generic[_Root]):
def __init__(self, element: Element | None = None, file: _FileRead | None = None) -> None: ...
def __init__(self, element: Element[Any] | None = None, file: _FileRead | None = None) -> None: ...
def getroot(self) -> _Root: ...
def parse(self, source: _FileRead, parser: XMLParser | None = None) -> Element: ...
def iter(self, tag: str | None = None) -> Generator[Element, None, None]: ...
@@ -186,7 +186,7 @@ HTML_EMPTY: Final[set[str]]
def register_namespace(prefix: str, uri: str) -> None: ...
@overload
def tostring(
element: Element,
element: Element[Any],
encoding: None = None,
method: Literal["xml", "html", "text", "c14n"] | None = None,
*,
@@ -196,7 +196,7 @@ def tostring(
) -> bytes: ...
@overload
def tostring(
element: Element,
element: Element[Any],
encoding: Literal["unicode"],
method: Literal["xml", "html", "text", "c14n"] | None = None,
*,
@@ -206,7 +206,7 @@ def tostring(
) -> str: ...
@overload
def tostring(
element: Element,
element: Element[Any],
encoding: str,
method: Literal["xml", "html", "text", "c14n"] | None = None,
*,
@@ -216,7 +216,7 @@ def tostring(
) -> Any: ...
@overload
def tostringlist(
element: Element,
element: Element[Any],
encoding: None = None,
method: Literal["xml", "html", "text", "c14n"] | None = None,
*,
@@ -226,7 +226,7 @@ def tostringlist(
) -> list[bytes]: ...
@overload
def tostringlist(
element: Element,
element: Element[Any],
encoding: Literal["unicode"],
method: Literal["xml", "html", "text", "c14n"] | None = None,
*,
@@ -236,7 +236,7 @@ def tostringlist(
) -> list[str]: ...
@overload
def tostringlist(
element: Element,
element: Element[Any],
encoding: str,
method: Literal["xml", "html", "text", "c14n"] | None = None,
*,
@@ -244,8 +244,8 @@ def tostringlist(
default_namespace: str | None = None,
short_empty_elements: bool = True,
) -> list[Any]: ...
def dump(elem: Element | ElementTree[Any]) -> None: ...
def indent(tree: Element | ElementTree[Any], space: str = " ", level: int = 0) -> None: ...
def dump(elem: Element[Any] | ElementTree[Any]) -> None: ...
def indent(tree: Element[Any] | ElementTree[Any], space: str = " ", level: int = 0) -> None: ...
def parse(source: _FileRead, parser: XMLParser[Any] | None = None) -> ElementTree[Element]: ...
# This class is defined inside the body of iterparse