From ce8ad27928c64106ba09225a1f8e770f9c1c4cd3 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 13 Feb 2023 23:01:22 -0500 Subject: [PATCH 1/2] type Element's and Document's appendChild and getElementsByTagName --- stdlib/xml/dom/minidom.pyi | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/stdlib/xml/dom/minidom.pyi b/stdlib/xml/dom/minidom.pyi index 7bbffb88c8f7..0db3cc9236ca 100644 --- a/stdlib/xml/dom/minidom.pyi +++ b/stdlib/xml/dom/minidom.pyi @@ -1,10 +1,14 @@ import sys import xml.dom from _typeshed import Incomplete, ReadableBuffer, SupportsRead, SupportsWrite +from typing import TypeVar from typing_extensions import Literal, Self +from xml.dom.minicompat import NodeList from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS from xml.sax.xmlreader import XMLReader +_N = TypeVar("_N", bound=Node) + def parse(file: str | SupportsRead[ReadableBuffer | str], parser: XMLReader | None = None, bufsize: int | None = None): ... def parseString(string: str | ReadableBuffer, parser: XMLReader | None = None): ... def getDOMImplementation(features=None) -> DOMImplementation | None: ... @@ -34,7 +38,7 @@ class Node(xml.dom.Node): def hasChildNodes(self) -> bool: ... def insertBefore(self, newChild, refChild): ... - def appendChild(self, node): ... + def appendChild(self, node: _N) -> _N: ... def replaceChild(self, newChild, oldChild): ... def removeChild(self, oldChild): ... def normalize(self) -> None: ... @@ -143,7 +147,7 @@ class Element(Node): removeAttributeNodeNS: Incomplete def hasAttribute(self, name: str) -> bool: ... def hasAttributeNS(self, namespaceURI: str, localName) -> bool: ... - def getElementsByTagName(self, name: str): ... + def getElementsByTagName(self, name: str) -> NodeList[Node]: ... def getElementsByTagNameNS(self, namespaceURI: str, localName): ... def writexml(self, writer: SupportsWrite[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... def hasAttributes(self) -> bool: ... @@ -300,7 +304,7 @@ class Document(Node, DocumentLS): doctype: DocumentType | None childNodes: Incomplete def __init__(self) -> None: ... - def appendChild(self, node): ... + def appendChild(self, node: _N) -> _N: ... documentElement: Incomplete def removeChild(self, oldChild): ... def unlink(self) -> None: ... @@ -315,7 +319,7 @@ class Document(Node, DocumentLS): def createElementNS(self, namespaceURI: str, qualifiedName: str): ... def createAttributeNS(self, namespaceURI: str, qualifiedName: str) -> Attr: ... def getElementById(self, id): ... - def getElementsByTagName(self, name: str): ... + def getElementsByTagName(self, name: str) -> NodeList[Node]: ... def getElementsByTagNameNS(self, namespaceURI: str, localName): ... def isSupported(self, feature: str, version: str | None) -> bool: ... def importNode(self, node, deep): ... From cd4c931a65fb5fdf8a9d9fe11f07e5ddd5f02031 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 13 Feb 2023 23:59:12 -0500 Subject: [PATCH 2/2] Fixed return types of Entity and Childless --- stdlib/xml/dom/minidom.pyi | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/stdlib/xml/dom/minidom.pyi b/stdlib/xml/dom/minidom.pyi index 0db3cc9236ca..ecc7bb6bcdf7 100644 --- a/stdlib/xml/dom/minidom.pyi +++ b/stdlib/xml/dom/minidom.pyi @@ -1,7 +1,7 @@ import sys import xml.dom from _typeshed import Incomplete, ReadableBuffer, SupportsRead, SupportsWrite -from typing import TypeVar +from typing import NoReturn, TypeVar from typing_extensions import Literal, Self from xml.dom.minicompat import NodeList from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS @@ -162,12 +162,12 @@ class Childless: childNodes: Incomplete firstChild: Incomplete lastChild: Incomplete - def appendChild(self, node) -> None: ... + def appendChild(self, node) -> NoReturn: ... def hasChildNodes(self) -> bool: ... - def insertBefore(self, newChild, refChild) -> None: ... - def removeChild(self, oldChild) -> None: ... + def insertBefore(self, newChild, refChild) -> NoReturn: ... + def removeChild(self, oldChild) -> NoReturn: ... def normalize(self) -> None: ... - def replaceChild(self, newChild, oldChild) -> None: ... + def replaceChild(self, newChild, oldChild) -> NoReturn: ... class ProcessingInstruction(Childless, Node): nodeType: int @@ -258,10 +258,10 @@ class Entity(Identified, Node): notationName: Incomplete childNodes: Incomplete def __init__(self, name, publicId, systemId, notation) -> None: ... - def appendChild(self, newChild) -> None: ... - def insertBefore(self, newChild, refChild) -> None: ... - def removeChild(self, oldChild) -> None: ... - def replaceChild(self, newChild, oldChild) -> None: ... + def appendChild(self, newChild) -> NoReturn: ... + def insertBefore(self, newChild, refChild) -> NoReturn: ... + def removeChild(self, oldChild) -> NoReturn: ... + def replaceChild(self, newChild, oldChild) -> NoReturn: ... class Notation(Identified, Childless, Node): nodeType: int