-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
_functions_overloads.pyi
117 lines (97 loc) · 3.98 KB
/
_functions_overloads.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# This file does not exist at runtime. It is a helper file to overload imported functions in openpyxl.xml.functions
import sys
from _typeshed import Incomplete, ReadableBuffer
from collections.abc import Iterable, Iterator, Mapping, Sequence
from typing import Any, Protocol, TypeVar, overload
from typing_extensions import TypeAlias
from xml.etree.ElementTree import Element, ElementTree, QName, XMLParser, _FileRead
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
# Useful protocols, see import comment in openpyxl/xml/functions.pyi
# Comment from openpyxl.cell.rich_text.py
# Usually an Element() from either lxml or xml.etree (has a 'tag' element)
class _HasTag(Protocol):
tag: Any # AnyOf[str, None, Callable[..., AnyOf[str, None]]]
class _HasText(Protocol):
text: str
class _HasTagAndGet(_HasTag, Protocol[_T_co]):
def get(self, __value: str) -> _T_co | None: ...
class _HasTagAndText(_HasTag, _HasText, Protocol): ... # noqa: Y046
class _HasTagAndTextAndAttrib(_HasTag, _HasText, Protocol): # noqa: Y046
attrib: Iterable[Any] # AnyOf[dict[str, str], Iterable[tuple[str, str]]]
class _ParentElement(Protocol[_T]):
def makeelement(self, __tag: str, __attrib: dict[str, str]) -> _T: ...
def append(self, __element: _T) -> object: ...
# from lxml.etree import _Element
_lxml_Element: TypeAlias = Element # noqa: Y042
# from lxml.etree import _ElementTree
_lxml_ElementTree: TypeAlias = ElementTree # noqa: Y042
# from lxml.etree import QName
_lxml_QName: TypeAlias = QName # noqa: Y042
# from xml.etree import fromstring
@overload
def SubElement(parent: _ParentElement[_T], tag: str, attrib: dict[str, str] = ..., **extra: str) -> _T: ...
# from lxml.etree import fromstring
@overload
def SubElement(
_parent: _lxml_Element, # This would be preferable as a protocol, but it's a C-Extension
_tag: str | bytes | _lxml_QName,
attrib: dict[str, str] | dict[bytes, bytes] | None = ...,
nsmap: Mapping[str, str] | None = ...,
**extra: str | bytes,
) -> _lxml_ElementTree: ...
# from xml.etree.ElementTree import fromstring
@overload
def fromstring(text: str | ReadableBuffer, parser: XMLParser | None = None) -> Element: ...
# from lxml.etree import fromstring
# But made partial, removing parser arg
@overload
def fromstring(text: str | bytes, *, base_url: str | bytes = ...) -> _lxml_Element: ... # type: ignore[misc] # Overlap with incompatible return types
# from defusedxml.ElementTree import fromstring
@overload
def fromstring(text: str, forbid_dtd: bool = False, forbid_entities: bool = True, forbid_external: bool = True) -> int: ...
# from xml.etree.ElementTree import tostring
# But made partial, removing encoding arg
if sys.version_info >= (3, 8):
@overload
def tostring(
element: Element,
method: str | None = "xml",
*,
xml_declaration: bool | None = None,
default_namespace: str | None = ...,
short_empty_elements: bool = ...,
) -> str: ...
else:
@overload
def tostring(element: Element, method: str | None = ..., *, short_empty_elements: bool = ...) -> str: ...
# from lxml.etree import Element
# But made partial, removing encoding arg
@overload
def tostring(
element_or_tree: _lxml_Element | _lxml_ElementTree,
method: str = ...,
xml_declaration: bool = ...,
pretty_print: bool = ...,
with_tail: bool = ...,
standalone: bool = ...,
doctype: str = ...,
exclusive: bool = ...,
with_comments: bool = ...,
inclusive_ns_prefixes: Incomplete = ...,
) -> bytes: ...
# from xml.etree.ElementTree import iterparse
@overload
def iterparse(
source: _FileRead, events: Sequence[str] | None = None, parser: XMLParser | None = None
) -> Iterator[tuple[str, Any]]: ...
# from defusedxml.ElementTree import iterparse
@overload
def iterparse(
source: _FileRead,
events: Sequence[str] | None = None,
parser: XMLParser | None = None,
forbid_dtd: bool = False,
forbid_entities: bool = True,
forbid_external: bool = True,
) -> Iterator[tuple[str, Any]]: ...