stdlib/xml/sax: Add type annotations (#10606)

* stdlib/xml/sax: Type annotations for commonly used methods.

* stdlib/xml/sax: More annotations.

It turns out SAX's definition of a "qname" is exactly the opposite of
ElementTree's. With that understanding, let's annotate the Attributes*Impl
classes too.

* stdlib/xml/sax: I better understand what AttributesNSImpl is doing now.

* Update third-party library stubs to agree with the new SAX annotations.
This commit is contained in:
Screwtapello
2023-09-23 13:08:13 +10:00
committed by GitHub
parent 41bfc12065
commit 49b717ca52
6 changed files with 109 additions and 93 deletions

View File

@@ -3,7 +3,7 @@ from collections.abc import Callable, Mapping, MutableMapping
from typing import Any
from typing_extensions import TypeAlias
from xml.sax import handler
from xml.sax.xmlreader import XMLReader
from xml.sax.xmlreader import AttributesImpl, XMLReader
from netaddr.core import Publisher, Subscriber
from netaddr.ip import IPAddress, IPNetwork, IPRange
@@ -14,7 +14,7 @@ IANA_INFO: dict[str, dict[_IanaInfoKey, dict[str, str]]]
class SaxRecordParser(handler.ContentHandler):
def __init__(self, callback: Callable[[Mapping[str, object] | None], object] | None = None) -> None: ...
def startElement(self, name: str, attrs: Mapping[str, object]) -> None: ...
def startElement(self, name: str, attrs: AttributesImpl) -> None: ...
def endElement(self, name: str) -> None: ...
def characters(self, content: str) -> None: ...

View File

@@ -1,7 +1,7 @@
from collections.abc import Iterator, Mapping
from typing import Any
from typing_extensions import Self
from xml.sax import handler
from xml.sax import handler, xmlreader
def is_string(x: object) -> bool: ...
@@ -29,7 +29,7 @@ class Handler(handler.ContentHandler):
root: Element
elements: list[Element]
def __init__(self) -> None: ...
def startElement(self, name: str, attributes: Mapping[str, Any]) -> None: ...
def startElement(self, name: str, attributes: xmlreader.AttributesImpl) -> None: ...
def endElement(self, name: str) -> None: ...
def characters(self, cdata: str) -> None: ...