Skip to content

Commit 04c0fba

Browse files
add missing type information, preserve generator tyyping
1 parent cb68990 commit 04c0fba

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

asyncstdlib/asynctools.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,17 @@ def __repr__(self) -> str:
119119
return f"<{self.__class__.__name__} of {self._iterator!r} at 0x{(id(self)):x}>"
120120

121121

122-
def borrow(iterator: AsyncIterator[T], /) -> AsyncIterator[T]:
122+
@overload
123+
def borrow(iterator: AsyncGenerator[T, S], /) -> AsyncGenerator[T, S]: ...
124+
125+
126+
@overload
127+
def borrow(iterator: AsyncIterator[T], /) -> AsyncIterator[T]: ...
128+
129+
130+
def borrow(
131+
iterator: Union[AsyncIterator[T], AsyncGenerator[T, Any]], /
132+
) -> Union[AsyncIterator[T], AsyncGenerator[T, Any]]:
123133
"""
124134
Borrow an async iterator, preventing to ``aclose`` it
125135
@@ -142,7 +152,7 @@ def borrow(iterator: AsyncIterator[T], /) -> AsyncIterator[T]:
142152
"borrowing requires an async iterator "
143153
+ f"with __aiter__ and __anext__ method, got {type(iterator).__name__}"
144154
)
145-
return _BorrowedAsyncIterator(iterator)
155+
return _BorrowedAsyncIterator[T, Any](iterator)
146156

147157

148158
def scoped_iter(iterable: AnyIterable[T], /) -> AsyncContextManager[AsyncIterator[T]]:

0 commit comments

Comments
 (0)