Skip to content

Commit

Permalink
Fix return type of _Element.iter* methods (GH-70)
Browse files Browse the repository at this point in the history
These methods return `Iterator` objects, not just `Iterable`s.
  • Loading branch information
Wuestengecko authored Aug 18, 2022
1 parent f71530a commit 0a9b609
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lxml-stubs/etree.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ class _Element(Iterable["_Element"], Sized):
def items(self) -> Sequence[Tuple[_AnyStr, _AnyStr]]: ...
def iter(
self, tag: Optional[_TagSelector] = ..., *tags: _TagSelector
) -> Iterable[_Element]: ...
) -> Iterator[_Element]: ...
iterancestors = iter
def iterchildren(
self,
tag: Optional[_TagSelector] = ...,
reversed: bool = False,
*tags: _TagSelector,
) -> Iterable[_Element]: ...
) -> Iterator[_Element]: ...
iterdescendants = iter
def iterfind(
self, path: str, namespaces: Optional[_NSMapArg] = ...
Expand All @@ -183,13 +183,13 @@ class _Element(Iterable["_Element"], Sized):
tag: Optional[_TagSelector] = ...,
preceding: bool = False,
*tags: _TagSelector,
) -> Iterable[_Element]: ...
) -> Iterator[_Element]: ...
def itertext(
self,
tag: Optional[_TagSelector] = ...,
with_tail: bool = False,
*tags: _TagSelector,
) -> Iterable[_AnyStr]: ...
) -> Iterator[_AnyStr]: ...
def keys(self) -> Sequence[_AnyStr]: ...
def makeelement(
self,
Expand Down Expand Up @@ -242,7 +242,7 @@ class _ElementTree:
def getroot(self) -> _Element: ...
def iter(
self, tag: Optional[_TagSelector] = ..., *tags: _TagSelector
) -> Iterable[_Element]: ...
) -> Iterator[_Element]: ...
def iterfind(
self, path: str, namespaces: Optional[_NSMapArg] = ...
) -> Iterator["_Element"]: ...
Expand Down
4 changes: 2 additions & 2 deletions test-data/test-etree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
main: |
from lxml import etree
element = etree.Element("foo")
reveal_type(element.iterchildren) # N: Revealed type is "def (tag: Union[builtins.str, builtins.bytes, lxml.etree.QName, Any, None] =, reversed: builtins.bool =, *tags: Union[builtins.str, builtins.bytes, lxml.etree.QName, Any]) -> typing.Iterable[lxml.etree._Element]"
reveal_type(element.iterchildren) # N: Revealed type is "def (tag: Union[builtins.str, builtins.bytes, lxml.etree.QName, Any, None] =, reversed: builtins.bool =, *tags: Union[builtins.str, builtins.bytes, lxml.etree.QName, Any]) -> typing.Iterator[lxml.etree._Element]"
result = element.iterchildren("my-attr")
reveal_type(result) # N: Revealed type is "typing.Iterable[lxml.etree._Element]"
reveal_type(result) # N: Revealed type is "typing.Iterator[lxml.etree._Element]"
- case: etree_xmlparser_makeelement
disable_cache: true
Expand Down

0 comments on commit 0a9b609

Please sign in to comment.