Skip to content
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

Add typing stubs for mypy compatibility #284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions xmltodict.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from typing import Any, Callable, Union, IO, Iterator, List, Tuple, Optional, Dict

class ParsingInterrupted(Exception): ...

class _DictSAXHandler:
path: List[Tuple[str, Dict[str, Any]]]
stack: List[Tuple[Optional[Dict[str, Any]], List[str]]]
data: List[str]
item: Optional[Dict[str, Any]]
item_depth: int
xml_attribs: bool
item_callback: Callable[..., Any]
attr_prefix: str
cdata_key: str
force_cdata: bool
cdata_separator: str
postprocessor: Optional[Callable[..., Any]]
dict_constructor: Callable[..., Any]
strip_whitespace: bool
namespace_separator: str
namespaces: Optional[Dict[str, str]]
force_list: Union[None, Tuple[str], Callable[..., Any]]
comment_key: str
def __init__(
self,
item_depth: int = ...,
item_callback: Callable[..., Any] = ...,
xml_attribs: bool = ...,
attr_prefix: str = ...,
cdata_key: str = ...,
force_cdata: bool = ...,
cdata_separator: str = ...,
postprocessor: Any | None = ...,
dict_constructor: Callable[..., Any] = ...,
strip_whitespace: bool = ...,
namespace_separator: str = ...,
namespaces: Any | None = ...,
force_list: Any | None = ...,
comment_key: str = ...,
): ...
def startNamespaceDecl(self, prefix: str, uri: str) -> None: ...
def startElement(
self, full_name: str, attrs: Union[Dict[str, Any], List[Any]]
) -> None: ...
def endElement(self, full_name: str) -> None: ...
def characters(self, data: str) -> None: ...
def comments(self, data: str) -> None: ...
def push_data(
self, item: Optional[Dict[str, Any]], key: str, data: Any
) -> Optional[Dict[str, Any]]: ...

def parse(
xml_input: Union[str, bytes, IO[str], Iterator[bytes]],
encoding: Optional[str] = ...,
expat: Any = ...,
process_namespaces: bool = ...,
namespace_separator: str = ...,
disable_entities: bool = ...,
process_comments: bool = ...,
**kwargs: Any
) -> Dict[str, Any]: ...
def unparse(
input_dict: Dict[str, Any],
output: Any | None = ...,
encoding: str = ...,
full_document: bool = ...,
short_empty_elements: bool = ...,
**kwargs: Any
) -> Optional[str]: ...