From db6e2a637be0c37c00f71ba2729815d0978e8141 Mon Sep 17 00:00:00 2001 From: rchen152 Date: Thu, 4 Jan 2018 19:04:46 -0800 Subject: [PATCH] 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. --- stdlib/2and3/xml/etree/ElementTree.pyi | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/stdlib/2and3/xml/etree/ElementTree.pyi b/stdlib/2and3/xml/etree/ElementTree.pyi index 4831ab0e0..9703c2049 100644 --- a/stdlib/2and3/xml/etree/ElementTree.pyi +++ b/stdlib/2and3/xml/etree/ElementTree.pyi @@ -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: ...