Fix some bugs in xml.etree.ElementTree.Element's container behavior. (#1816)

* Have Element inherit from MutableSequence, which is more precise than Sequence.
* Remove unnecessary inherited methods (e.g., __getitem__).
* Correct extend() to take an Iterable. (Sequence was too specific.)
* Alphabetize the typing imports, for sanity.
This commit is contained in:
rchen152
2018-01-04 19:04:46 -08:00
committed by Matthias Kramm
parent 29acda6431
commit db6e2a637b

View File

@@ -1,6 +1,6 @@
# Stubs for xml.etree.ElementTree
from typing import Any, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator, Text
from typing import Any, Callable, Dict, Generator, IO, ItemsView, Iterable, Iterator, KeysView, List, MutableSequence, Optional, Sequence, Text, Tuple, TypeVar, Union
import io
import sys
@@ -41,7 +41,7 @@ else:
# On the bright side, tostring and tostringlist always return bytes:
_tostring_result_type = bytes
class Element(Sequence['Element']):
class Element(MutableSequence['Element']):
tag = ... # type: _str_result_type
attrib = ... # type: Dict[_str_result_type, _str_result_type]
text = ... # type: Optional[_str_result_type]
@@ -50,7 +50,7 @@ class Element(Sequence['Element']):
def append(self, subelement: 'Element') -> None: ...
def clear(self) -> None: ...
def copy(self) -> 'Element': ...
def extend(self, elements: Sequence['Element']) -> None: ...
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]: ...
@@ -70,10 +70,6 @@ class Element(Sequence['Element']):
def remove(self, subelement: 'Element') -> None: ...
def set(self, key: _str_argument_type, value: _str_argument_type) -> None: ...
def __bool__(self) -> bool: ...
def __delitem__(self, index: int) -> None: ...
def __getitem__(self, index) -> 'Element': ...
def __len__(self) -> int: ...
def __setitem__(self, index: int, element: 'Element') -> None: ...
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: ...