mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
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:
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user