Skip to content

refactor: expand types in xml module #8590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 22, 2022
84 changes: 42 additions & 42 deletions stdlib/xml/dom/minidom.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import xml.dom
from _typeshed import Self, SupportsRead
from _typeshed import Incomplete, Self, SupportsRead, SupportsWrite
from typing import Any
from typing_extensions import Literal
from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS
Expand All @@ -25,11 +25,11 @@ class Node(xml.dom.Node):
def localName(self) -> str | None: ...
def __bool__(self) -> Literal[True]: ...
if sys.version_info >= (3, 9):
def toxml(self, encoding: Any | None = ..., standalone: Any | None = ...): ...
def toprettyxml(self, indent: str = ..., newl: str = ..., encoding: Any | None = ..., standalone: Any | None = ...): ...
def toxml(self, encoding: str | None = ..., standalone: bool | None = ...): ...
def toprettyxml(self, indent: str = ..., newl: str = ..., encoding: str | None = ..., standalone: bool | None = ...): ...
else:
def toxml(self, encoding: Any | None = ...): ...
def toprettyxml(self, indent: str = ..., newl: str = ..., encoding: Any | None = ...): ...
def toxml(self, encoding: str | None = ...): ...
def toprettyxml(self, indent: str = ..., newl: str = ..., encoding: str | None = ...): ...

def hasChildNodes(self) -> bool: ...
def insertBefore(self, newChild, refChild): ...
Expand Down Expand Up @@ -70,7 +70,7 @@ class Attr(Node):
value: str
prefix: Any
def __init__(
self, qName: str, namespaceURI: str | None = ..., localName: Any | None = ..., prefix: Any | None = ...
self, qName: str, namespaceURI: str | None = ..., localName: str | None = ..., prefix: Any | None = ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The localName argument is actually ignored: https://github.com/python/cpython/blob/18b1782192f85bd26db89f5bc850f8bee4247c1a/Lib/xml/dom/minidom.py#L355.

Seems like it wants a if localName is not None: self._localName = localName. Are you interested in contributing that to CPython?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'm happy to give that a shot.

Issue:
python/cpython#96175

PR:
python/cpython#96176

) -> None: ...
def unlink(self) -> None: ...
@property
Expand All @@ -87,31 +87,31 @@ class NamedNodeMap:
def keys(self): ...
def keysNS(self): ...
def values(self): ...
def get(self, name, value: Any | None = ...): ...
def get(self, name: str, value: Any | None = ...): ...
def __len__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: Any) -> bool: ...
def __gt__(self, other: Any) -> bool: ...
def __le__(self, other: Any) -> bool: ...
def __lt__(self, other: Any) -> bool: ...
def __getitem__(self, attname_or_tuple): ...
def __setitem__(self, attname, value) -> None: ...
def getNamedItem(self, name): ...
def getNamedItemNS(self, namespaceURI: str, localName): ...
def removeNamedItem(self, name): ...
def removeNamedItemNS(self, namespaceURI: str, localName): ...
def setNamedItem(self, node): ...
def setNamedItemNS(self, node): ...
def __delitem__(self, attname_or_tuple) -> None: ...
def __ge__(self, other: NamedNodeMap) -> bool: ...
def __gt__(self, other: NamedNodeMap) -> bool: ...
def __le__(self, other: NamedNodeMap) -> bool: ...
def __lt__(self, other: NamedNodeMap) -> bool: ...
def __getitem__(self, attname_or_tuple: tuple[str, str | None] | str): ...
def __setitem__(self, attname: str, value: Attr | str) -> None: ...
def getNamedItem(self, name: str) -> Attr | None: ...
def getNamedItemNS(self, namespaceURI: str, localName: str | None) -> Attr | None: ...
def removeNamedItem(self, name: str) -> Attr: ...
def removeNamedItemNS(self, namespaceURI: str, localName: str | None): ...
def setNamedItem(self, node: Attr) -> Attr: ...
def setNamedItemNS(self, node: Attr) -> Attr: ...
def __delitem__(self, attname_or_tuple: tuple[str, str | None] | str) -> None: ...
@property
def length(self) -> int: ...

AttributeList = NamedNodeMap

class TypeInfo:
namespace: Any
name: Any
def __init__(self, namespace, name) -> None: ...
namespace: Incomplete | None
name: str
def __init__(self, namespace: Incomplete | None, name: str) -> None: ...

class Element(Node):
nodeType: int
Expand Down Expand Up @@ -144,7 +144,7 @@ class Element(Node):
def hasAttributeNS(self, namespaceURI: str, localName) -> bool: ...
def getElementsByTagName(self, name: str): ...
def getElementsByTagNameNS(self, namespaceURI: str, localName): ...
def writexml(self, writer, indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...
def writexml(self, writer: SupportsWrite[str], indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...
def hasAttributes(self) -> bool: ...
def setIdAttribute(self, name) -> None: ...
def setIdAttributeNS(self, namespaceURI: str, localName) -> None: ...
Expand All @@ -171,7 +171,7 @@ class ProcessingInstruction(Childless, Node):
def __init__(self, target, data) -> None: ...
nodeValue: Any
nodeName: Any
def writexml(self, writer, indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...
def writexml(self, writer: SupportsWrite[str], indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...

class CharacterData(Childless, Node):
ownerDocument: Any
Expand All @@ -194,7 +194,7 @@ class Text(CharacterData):
attributes: Any
data: Any
def splitText(self, offset): ...
def writexml(self, writer, indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...
def writexml(self, writer: SupportsWrite[str], indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...
def replaceWholeText(self, content): ...
@property
def isWhitespaceInElementContent(self) -> bool: ...
Expand All @@ -205,12 +205,12 @@ class Comment(CharacterData):
nodeType: int
nodeName: str
def __init__(self, data) -> None: ...
def writexml(self, writer, indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...
def writexml(self, writer: SupportsWrite[str], indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...

class CDATASection(Text):
nodeType: int
nodeName: str
def writexml(self, writer, indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...
def writexml(self, writer: SupportsWrite[str], indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...

class ReadOnlySequentialNamedNodeMap:
def __init__(self, seq=...) -> None: ...
Expand Down Expand Up @@ -240,7 +240,7 @@ class DocumentType(Identified, Childless, Node):
nodeName: Any
def __init__(self, qualifiedName: str) -> None: ...
def cloneNode(self, deep): ...
def writexml(self, writer, indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...
def writexml(self, writer: SupportsWrite[str], indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...

class Entity(Identified, Node):
attributes: Any
Expand Down Expand Up @@ -290,47 +290,47 @@ class Document(Node, DocumentLS):
previousSibling: Any
nextSibling: Any
actualEncoding: Any
encoding: Any
standalone: Any
encoding: str | None
standalone: bool | None
version: Any
strictErrorChecking: bool
errorHandler: Any
documentURI: Any
doctype: Any
doctype: DocumentType | None
childNodes: Any
def __init__(self) -> None: ...
def appendChild(self, node): ...
documentElement: Any
def removeChild(self, oldChild): ...
def unlink(self) -> None: ...
def cloneNode(self, deep): ...
def createDocumentFragment(self): ...
def createElement(self, tagName: str): ...
def createTextNode(self, data): ...
def createCDATASection(self, data): ...
def createComment(self, data): ...
def createDocumentFragment(self) -> DocumentFragment: ...
def createElement(self, tagName: str) -> Element: ...
def createTextNode(self, data: str) -> Text: ...
def createCDATASection(self, data: str) -> CDATASection: ...
def createComment(self, data: str) -> Comment: ...
def createProcessingInstruction(self, target, data): ...
def createAttribute(self, qName) -> Attr: ...
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 getElementsByTagNameNS(self, namespaceURI: str, localName): ...
def isSupported(self, feature, version): ...
def isSupported(self, feature: str, version: str | None) -> bool: ...
def importNode(self, node, deep): ...
if sys.version_info >= (3, 9):
def writexml(
self,
writer,
writer: SupportsWrite[str],
indent: str = ...,
addindent: str = ...,
newl: str = ...,
encoding: Any | None = ...,
standalone: Any | None = ...,
encoding: str | None = ...,
standalone: bool | None = ...,
) -> None: ...
else:
def writexml(
self, writer, indent: str = ..., addindent: str = ..., newl: str = ..., encoding: Any | None = ...
self, writer: SupportsWrite[str], indent: str = ..., addindent: str = ..., newl: str = ..., encoding: Any | None = ...
) -> None: ...

def renameNode(self, n, namespaceURI: str, name): ...
7 changes: 4 additions & 3 deletions stdlib/xml/sax/handler.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import sys
from typing import NoReturn

version: str

class ErrorHandler:
def error(self, exception): ...
def fatalError(self, exception): ...
def warning(self, exception): ...
def error(self, exception: BaseException) -> NoReturn: ...
def fatalError(self, exception: BaseException) -> NoReturn: ...
def warning(self, exception: BaseException) -> None: ...

class ContentHandler:
def __init__(self) -> None: ...
Expand Down