diff --git a/stubs/xmltodict/@tests/test_cases/check_postprocessor.py b/stubs/xmltodict/@tests/test_cases/check_postprocessor.py new file mode 100644 index 000000000000..805a7aae7d14 --- /dev/null +++ b/stubs/xmltodict/@tests/test_cases/check_postprocessor.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +import xmltodict +from xmltodict import _AttrDict, _AttrValue + + +# XML post-processor that eats all `b` elements +def b_eater(path: list[tuple[str, _AttrDict | None]], key: str, value: _AttrValue) -> tuple[str, _AttrValue] | None: + if key == "b": + return None # discard the node entirely + return key, value + + +xmltodict.parse("", postprocessor=b_eater) +# returns a tree of just diff --git a/stubs/xmltodict/xmltodict.pyi b/stubs/xmltodict/xmltodict.pyi index d0e1237d3360..50ba4b6f4fbe 100644 --- a/stubs/xmltodict/xmltodict.pyi +++ b/stubs/xmltodict/xmltodict.pyi @@ -20,7 +20,7 @@ class _DictSAXHandler: cdata_key: str force_cdata: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool] cdata_separator: str - postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue]] | None + postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue] | None] | None dict_constructor: type strip_whitespace: bool namespace_separator: str @@ -37,7 +37,9 @@ class _DictSAXHandler: cdata_key: str = "#text", force_cdata: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool] = False, cdata_separator: str = "", - postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue]] | None = None, + postprocessor: ( + Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue] | None] | None + ) = None, dict_constructor: type = ..., strip_whitespace: bool = True, namespace_separator: str = ":", @@ -68,7 +70,7 @@ def parse( cdata_key: str = "#text", force_cdata: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool] = False, cdata_separator: str = "", - postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue]] | None = None, + postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue] | None] | None = None, dict_constructor: type = ..., strip_whitespace: bool = True, namespaces: Mapping[str, str | None] | None = None,