mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-06 12:14:27 +08:00
Add missing explicit Optional to stubs for the xml.etree package. (#2734)
Fixes #2733
This commit is contained in:
committed by
Sebastian Rittau
parent
e8c1111d13
commit
a2ecfafa98
@@ -14,4 +14,4 @@ def default_loader(href: Union[str, bytes, int], parse: str, encoding: Optional[
|
||||
# TODO: loader is of type default_loader ie it takes a callable that has the
|
||||
# same signature as default_loader. But default_loader has a keyword argument
|
||||
# Which can't be represented using Callable...
|
||||
def include(elem: Element, loader: Callable[..., Union[str, Element]] = ...) -> None: ...
|
||||
def include(elem: Element, loader: Optional[Callable[..., Union[str, Element]]] = ...) -> None: ...
|
||||
|
||||
@@ -9,7 +9,7 @@ _token = Tuple[str, str]
|
||||
_next = Callable[[], _token]
|
||||
_callback = Callable[[_SelectorContext, List[Element]], Generator[Element, None, None]]
|
||||
|
||||
def xpath_tokenizer(pattern: str, namespaces: Dict[str, str] = ...) -> Generator[_token, None, None]: ...
|
||||
def xpath_tokenizer(pattern: str, namespaces: Optional[Dict[str, str]] = ...) -> Generator[_token, None, None]: ...
|
||||
def get_parent_map(context: _SelectorContext) -> Dict[Element, Element]: ...
|
||||
def prepare_child(next: _next, token: _token) -> _callback: ...
|
||||
def prepare_star(next: _next, token: _token) -> _callback: ...
|
||||
@@ -27,7 +27,7 @@ class _SelectorContext:
|
||||
|
||||
_T = TypeVar('_T')
|
||||
|
||||
def iterfind(elem: Element, path: str, namespaces: Dict[str, str] = ...) -> List[Element]: ...
|
||||
def find(elem: Element, path: str, namespaces: Dict[str, str] = ...) -> Optional[Element]: ...
|
||||
def findall(elem: Element, path: str, namespaces: Dict[str, str] = ...) -> List[Element]: ...
|
||||
def findtext(elem: Element, path: str, default: _T = ..., namespaces: Dict[str, str] = ...) -> Union[_T, str]: ...
|
||||
def iterfind(elem: Element, path: str, namespaces: Optional[Dict[str, str]] = ...) -> List[Element]: ...
|
||||
def find(elem: Element, path: str, namespaces: Optional[Dict[str, str]] = ...) -> Optional[Element]: ...
|
||||
def findall(elem: Element, path: str, namespaces: Optional[Dict[str, str]] = ...) -> List[Element]: ...
|
||||
def findtext(elem: Element, path: str, default: Optional[_T] = ..., namespaces: Optional[Dict[str, str]] = ...) -> Union[_T, str]: ...
|
||||
|
||||
@@ -51,19 +51,19 @@ class Element(MutableSequence[Element]):
|
||||
def clear(self) -> None: ...
|
||||
def copy(self) -> Element: ...
|
||||
def extend(self, elements: Iterable[Element]) -> None: ...
|
||||
def find(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type] = ...) -> Optional[Element]: ...
|
||||
def findall(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type] = ...) -> List[Element]: ...
|
||||
def findtext(self, path: _str_argument_type, default: _T = ..., namespaces: Dict[_str_argument_type, _str_argument_type] = ...) -> Union[_T, _str_result_type]: ...
|
||||
def get(self, key: _str_argument_type, default: _T = ...) -> Union[_str_result_type, _T]: ...
|
||||
def find(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Optional[Element]: ...
|
||||
def findall(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> List[Element]: ...
|
||||
def findtext(self, path: _str_argument_type, default: Optional[_T] = ..., namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Union[_T, _str_result_type]: ...
|
||||
def get(self, key: _str_argument_type, default: Optional[_T] = ...) -> Union[_str_result_type, _T]: ...
|
||||
def getchildren(self) -> List[Element]: ...
|
||||
def getiterator(self, tag: _str_argument_type = ...) -> List[Element]: ...
|
||||
def getiterator(self, tag: Optional[_str_argument_type] = ...) -> List[Element]: ...
|
||||
if sys.version_info >= (3, 2):
|
||||
def insert(self, index: int, subelement: Element) -> None: ...
|
||||
else:
|
||||
def insert(self, index: int, element: Element) -> None: ...
|
||||
def items(self) -> ItemsView[_str_result_type, _str_result_type]: ...
|
||||
def iter(self, tag: _str_argument_type = ...) -> Generator[Element, None, None]: ...
|
||||
def iterfind(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type] = ...) -> List[Element]: ...
|
||||
def iter(self, tag: Optional[_str_argument_type] = ...) -> Generator[Element, None, None]: ...
|
||||
def iterfind(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> List[Element]: ...
|
||||
def itertext(self) -> Generator[_str_result_type, None, None]: ...
|
||||
def keys(self) -> KeysView[_str_result_type]: ...
|
||||
def makeelement(self, tag: _str_argument_type, attrib: Dict[_str_argument_type, _str_argument_type]) -> Element: ...
|
||||
@@ -83,59 +83,59 @@ class Element(MutableSequence[Element]):
|
||||
|
||||
|
||||
def SubElement(parent: Element, tag: _str_argument_type, attrib: Dict[_str_argument_type, _str_argument_type] = ..., **extra: _str_argument_type) -> Element: ...
|
||||
def Comment(text: _str_argument_type = ...) -> Element: ...
|
||||
def ProcessingInstruction(target: _str_argument_type, text: _str_argument_type = ...) -> Element: ...
|
||||
def Comment(text: Optional[_str_argument_type] = ...) -> Element: ...
|
||||
def ProcessingInstruction(target: _str_argument_type, text: Optional[_str_argument_type] = ...) -> Element: ...
|
||||
|
||||
PI = ... # type: Callable[..., Element]
|
||||
|
||||
class QName:
|
||||
text = ... # type: str
|
||||
def __init__(self, text_or_uri: _str_argument_type, tag: _str_argument_type = ...) -> None: ...
|
||||
def __init__(self, text_or_uri: _str_argument_type, tag: Optional[_str_argument_type] = ...) -> None: ...
|
||||
|
||||
|
||||
_file_or_filename = Union[str, bytes, int, IO[Any]]
|
||||
|
||||
class ElementTree:
|
||||
def __init__(self, element: Element = ..., file: _file_or_filename = ...) -> None: ...
|
||||
def __init__(self, element: Optional[Element] = ..., file: Optional[_file_or_filename] = ...) -> None: ...
|
||||
def getroot(self) -> Element: ...
|
||||
def parse(self, source: _file_or_filename, parser: XMLParser = ...) -> Element: ...
|
||||
def iter(self, tag: _str_argument_type = ...) -> Generator[Element, None, None]: ...
|
||||
def getiterator(self, tag: _str_argument_type = ...) -> List[Element]: ...
|
||||
def find(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type] = ...) -> Optional[Element]: ...
|
||||
def findtext(self, path: _str_argument_type, default: _T = ..., namespaces: Dict[_str_argument_type, _str_argument_type] = ...) -> Union[_T, _str_result_type]: ...
|
||||
def findall(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type] = ...) -> List[Element]: ...
|
||||
def iterfind(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type] = ...) -> List[Element]: ...
|
||||
def parse(self, source: _file_or_filename, parser: Optional[XMLParser] = ...) -> Element: ...
|
||||
def iter(self, tag: Optional[_str_argument_type] = ...) -> Generator[Element, None, None]: ...
|
||||
def getiterator(self, tag: Optional[_str_argument_type] = ...) -> List[Element]: ...
|
||||
def find(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Optional[Element]: ...
|
||||
def findtext(self, path: _str_argument_type, default: Optional[_T] = ..., namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Union[_T, _str_result_type]: ...
|
||||
def findall(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> List[Element]: ...
|
||||
def iterfind(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> List[Element]: ...
|
||||
if sys.version_info >= (3, 4):
|
||||
def write(self, file_or_filename: _file_or_filename, encoding: str = ..., xml_declaration: Optional[bool] = ..., default_namespace: _str_argument_type = ..., method: str = ..., *, short_empty_elements: bool = ...) -> None: ...
|
||||
def write(self, file_or_filename: _file_or_filename, encoding: Optional[str] = ..., xml_declaration: Optional[bool] = ..., default_namespace: Optional[_str_argument_type] = ..., method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> None: ...
|
||||
else:
|
||||
def write(self, file_or_filename: _file_or_filename, encoding: str = ..., xml_declaration: Optional[bool] = ..., default_namespace: _str_argument_type = ..., method: str = ...) -> None: ...
|
||||
def write(self, file_or_filename: _file_or_filename, encoding: Optional[str] = ..., xml_declaration: Optional[bool] = ..., default_namespace: Optional[_str_argument_type] = ..., method: Optional[str] = ...) -> None: ...
|
||||
def write_c14n(self, file: _file_or_filename) -> None: ...
|
||||
|
||||
def register_namespace(prefix: _str_argument_type, uri: _str_argument_type) -> None: ...
|
||||
if sys.version_info >= (3, 4):
|
||||
def tostring(element: Element, encoding: str = ..., method: str = ..., *, short_empty_elements: bool = ...) -> _tostring_result_type: ...
|
||||
def tostringlist(element: Element, encoding: str = ..., method: str = ..., *, short_empty_elements: bool = ...) -> List[_tostring_result_type]: ...
|
||||
def tostring(element: Element, encoding: Optional[str] = ..., method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> _tostring_result_type: ...
|
||||
def tostringlist(element: Element, encoding: Optional[str] = ..., method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> List[_tostring_result_type]: ...
|
||||
else:
|
||||
def tostring(element: Element, encoding: str = ..., method: str = ...) -> _tostring_result_type: ...
|
||||
def tostringlist(element: Element, encoding: str = ..., method: str = ...) -> List[_tostring_result_type]: ...
|
||||
def tostring(element: Element, encoding: Optional[str] = ..., method: Optional[str] = ...) -> _tostring_result_type: ...
|
||||
def tostringlist(element: Element, encoding: Optional[str] = ..., method: Optional[str] = ...) -> List[_tostring_result_type]: ...
|
||||
def dump(elem: Element) -> None: ...
|
||||
def parse(source: _file_or_filename, parser: XMLParser = ...) -> ElementTree: ...
|
||||
def iterparse(source: _file_or_filename, events: Sequence[str] = ..., parser: XMLParser = ...) -> Iterator[Tuple[str, Any]]: ...
|
||||
def parse(source: _file_or_filename, parser: Optional[XMLParser] = ...) -> ElementTree: ...
|
||||
def iterparse(source: _file_or_filename, events: Optional[Sequence[str]] = ..., parser: Optional[XMLParser] = ...) -> Iterator[Tuple[str, Any]]: ...
|
||||
|
||||
if sys.version_info >= (3, 4):
|
||||
class XMLPullParser:
|
||||
def __init__(self, events: Sequence[str] = ..., *, _parser: XMLParser = ...) -> None: ...
|
||||
def __init__(self, events: Optional[Sequence[str]] = ..., *, _parser: Optional[XMLParser] = ...) -> None: ...
|
||||
def feed(self, data: bytes) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
def read_events(self) -> Iterator[Tuple[str, Element]]: ...
|
||||
|
||||
def XML(text: _parser_input_type, parser: XMLParser = ...) -> Element: ...
|
||||
def XMLID(text: _parser_input_type, parser: XMLParser = ...) -> Tuple[Element, Dict[_str_result_type, Element]]: ...
|
||||
def XML(text: _parser_input_type, parser: Optional[XMLParser] = ...) -> Element: ...
|
||||
def XMLID(text: _parser_input_type, parser: Optional[XMLParser] = ...) -> Tuple[Element, Dict[_str_result_type, Element]]: ...
|
||||
|
||||
# This is aliased to XML in the source.
|
||||
fromstring = XML
|
||||
|
||||
def fromstringlist(sequence: Sequence[_parser_input_type], parser: XMLParser = ...) -> Element: ...
|
||||
def fromstringlist(sequence: Sequence[_parser_input_type], parser: Optional[XMLParser] = ...) -> Element: ...
|
||||
|
||||
# This type is both not precise enough and too precise. The TreeBuilder
|
||||
# requires the elementfactory to accept tag and attrs in its args and produce
|
||||
@@ -149,7 +149,7 @@ def fromstringlist(sequence: Sequence[_parser_input_type], parser: XMLParser = .
|
||||
_ElementFactory = Callable[[Any, Dict[Any, Any]], Element]
|
||||
|
||||
class TreeBuilder:
|
||||
def __init__(self, element_factory: _ElementFactory = ...) -> None: ...
|
||||
def __init__(self, element_factory: Optional[_ElementFactory] = ...) -> None: ...
|
||||
def close(self) -> Element: ...
|
||||
def data(self, data: _parser_input_type) -> None: ...
|
||||
def start(self, tag: _parser_input_type, attrs: Dict[_parser_input_type, _parser_input_type]) -> Element: ...
|
||||
@@ -161,7 +161,7 @@ class XMLParser:
|
||||
# TODO-what is entity used for???
|
||||
entity = ... # type: Any
|
||||
version = ... # type: str
|
||||
def __init__(self, html: int = ..., target: TreeBuilder = ..., encoding: str = ...) -> None: ...
|
||||
def __init__(self, html: int = ..., target: Optional[TreeBuilder] = ..., encoding: Optional[str] = ...) -> None: ...
|
||||
def doctype(self, name: str, pubid: str, system: str) -> None: ...
|
||||
def close(self) -> Element: ...
|
||||
def feed(self, data: _parser_input_type) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user