Skip to content

Commit 15bc02e

Browse files
authored
[xmltodict] stub improvements and update to 1.0.1 (#14695)
1 parent d79b8d0 commit 15bc02e

File tree

2 files changed

+75
-28
lines changed

2 files changed

+75
-28
lines changed

stubs/xmltodict/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = "1.0.*"
1+
version = "~= 1.0.1"
22
upstream_repository = "https://github.com/martinblech/xmltodict"

stubs/xmltodict/xmltodict.pyi

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
1-
from _typeshed import Incomplete, ReadableBuffer, SupportsRead, SupportsWrite
2-
from collections import OrderedDict
3-
from collections.abc import Mapping
4-
from types import GeneratorType
5-
from typing import Any, Final, overload
6-
7-
__author__: Final[str]
8-
__version__: Final[str]
9-
__license__: Final[str]
1+
from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite
2+
from collections.abc import Callable, Container, Generator, Mapping
3+
from typing import Any, overload
4+
from typing_extensions import TypeAlias
105

116
class ParsingInterrupted(Exception): ...
127

8+
# dict as attribute value is exclusive to xmlns: https://github.com/bigpick/xmltodict/commit/22541b4874365cb8d2397f23087a866b3081fd9c
9+
_AttrValue: TypeAlias = str | dict[str, str]
10+
_AttrDict: TypeAlias = dict[str, _AttrValue]
11+
12+
class _DictSAXHandler:
13+
path: list[tuple[str, _AttrDict | None]]
14+
stack: list[tuple[_AttrDict | None, list[str]]]
15+
data: list[str]
16+
item: _AttrDict | None
17+
item_depth: int
18+
xml_attribs: bool
19+
item_callback: Callable[[list[tuple[str, _AttrDict | None]], str | _AttrDict | None], bool]
20+
attr_prefix: str
21+
cdata_key: str
22+
force_cdata: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool]
23+
cdata_separator: str
24+
postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue]] | None
25+
dict_constructor: type
26+
strip_whitespace: bool
27+
namespace_separator: str
28+
namespaces: dict[str, str] | None
29+
namespace_declarations: dict[str, str]
30+
force_list: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool] | None
31+
comment_key: str
32+
def __init__(
33+
self,
34+
item_depth: int = 0,
35+
item_callback: Callable[[list[tuple[str, _AttrDict | None]], str | _AttrDict | None], bool] = ...,
36+
xml_attribs: bool = True,
37+
attr_prefix: str = "@",
38+
cdata_key: str = "#text",
39+
force_cdata: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool] = False,
40+
cdata_separator: str = "",
41+
postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue]] | None = None,
42+
dict_constructor: type = ...,
43+
strip_whitespace: bool = True,
44+
namespace_separator: str = ":",
45+
namespaces: dict[str, str] | None = None,
46+
force_list: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool] | None = None,
47+
comment_key: str = "#comment",
48+
) -> None: ...
49+
def startNamespaceDecl(self, prefix: str, uri: str) -> None: ...
50+
def startElement(self, full_name: str, attrs: dict[str, str] | list[str]) -> None: ...
51+
def endElement(self, full_name: str) -> None: ...
52+
def characters(self, data: str) -> None: ...
53+
def comments(self, data: str) -> None: ...
54+
def push_data(self, item: _AttrDict | None, key: str, data: str) -> _AttrDict: ...
55+
1356
def parse(
14-
xml_input: str | ReadableBuffer | SupportsRead[bytes] | GeneratorType[ReadableBuffer, Any, Any],
57+
xml_input: str | ReadableBuffer | SupportsRead[bytes] | Generator[ReadableBuffer],
1558
encoding: str | None = None,
1659
expat: Any = ...,
1760
process_namespaces: bool = False,
@@ -20,19 +63,19 @@ def parse(
2063
process_comments: bool = False,
2164
*,
2265
item_depth: int = 0,
23-
item_callback=...,
66+
item_callback: Callable[[list[tuple[str, _AttrDict | None]], str | _AttrDict | None], bool] = ...,
2467
xml_attribs: bool = True,
25-
attr_prefix="@",
26-
cdata_key="#text",
27-
force_cdata: bool | Incomplete = False,
28-
cdata_separator="",
29-
postprocessor=None,
68+
attr_prefix: str = "@",
69+
cdata_key: str = "#text",
70+
force_cdata: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool] = False,
71+
cdata_separator: str = "",
72+
postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue]] | None = None,
3073
dict_constructor: type = ...,
3174
strip_whitespace: bool = True,
32-
namespaces=None,
33-
force_list: bool | Incomplete = None,
75+
namespaces: dict[str, str] | None = None,
76+
force_list: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool] | None = None,
3477
comment_key: str = "#comment",
35-
) -> OrderedDict[str, Any]: ...
78+
) -> dict[str, Any]: ...
3679
@overload
3780
def unparse(
3881
input_dict: Mapping[str, Any],
@@ -43,15 +86,17 @@ def unparse(
4386
comment_key: str = "#comment",
4487
*,
4588
attr_prefix: str = "@",
46-
cdata_key="#text",
89+
cdata_key: str = "#text",
4790
depth: int = 0,
48-
preprocessor=None,
91+
# preprocessor is called like (preprocessor(key, value) for key, value in input_dict.items()).
92+
# It is expected to return its input, or a modification thereof
93+
preprocessor: Callable[[str, Any], tuple[str, Any]] | None = None,
4994
pretty: bool = False,
5095
newl: str = "\n",
5196
indent: str | int = "\t",
5297
namespace_separator: str = ":",
53-
namespaces=None,
54-
expand_iter=None,
98+
namespaces: Mapping[str, str] | None = None,
99+
expand_iter: str | None = None,
55100
) -> None: ...
56101
@overload
57102
def unparse(
@@ -63,13 +108,15 @@ def unparse(
63108
comment_key: str = "#comment",
64109
*,
65110
attr_prefix: str = "@",
66-
cdata_key="#text",
111+
cdata_key: str = "#text",
67112
depth: int = 0,
68-
preprocessor=None,
113+
# preprocessor is called like (preprocessor(key, value) for key, value in input_dict.items()).
114+
# It is expected to return its input, or a modification thereof
115+
preprocessor: Callable[[str, Any], tuple[str, Any]] | None = None,
69116
pretty: bool = False,
70117
newl: str = "\n",
71118
indent: str | int = "\t",
72119
namespace_separator: str = ":",
73-
namespaces=None,
74-
expand_iter=None,
120+
namespaces: Mapping[str, str] | None = None,
121+
expand_iter: str | None = None,
75122
) -> str: ...

0 commit comments

Comments
 (0)