Skip to content

Commit 90389c2

Browse files
type hint non-suppressing contexts (closes #143)
1 parent 1e5bbbb commit 90389c2

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

asyncstdlib/asynctools.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,9 @@ async def __aenter__(self) -> AsyncIterator[T]:
110110
self._borrowed_iter = _ScopedAsyncIterator(self._iterator)
111111
return self._borrowed_iter
112112

113-
async def __aexit__(self, *args: Any) -> bool:
113+
async def __aexit__(self, *args: Any) -> None:
114114
await self._borrowed_iter._aclose_wrapper() # type: ignore
115115
await self._iterator.aclose() # type: ignore
116-
return False
117116

118117
def __repr__(self) -> str:
119118
return f"<{self.__class__.__name__} of {self._iterator!r} at 0x{(id(self)):x}>"

asyncstdlib/contextlib.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ def __init__(self, thing: AClose):
199199
async def __aenter__(self) -> AClose:
200200
return self.thing
201201

202-
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool:
202+
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
203203
await self.thing.aclose()
204-
return False
205204

206205

207206
closing = Closing
@@ -239,8 +238,8 @@ def __init__(self, enter_result: T = None):
239238
async def __aenter__(self) -> T:
240239
return self.enter_result
241240

242-
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool:
243-
return False
241+
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
242+
return None
244243

245244

246245
nullcontext = NullContext

asyncstdlib/contextlib.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class closing(Generic[AClose]):
6666
exc_type: type[BaseException] | None,
6767
exc_val: BaseException | None,
6868
exc_tb: TracebackType | None,
69-
) -> bool: ...
69+
) -> None: ...
7070

7171
class nullcontext(AsyncContextManager[T]):
7272
enter_result: T
@@ -84,7 +84,7 @@ class nullcontext(AsyncContextManager[T]):
8484
exc_type: type[BaseException] | None,
8585
exc_val: BaseException | None,
8686
exc_tb: TracebackType | None,
87-
) -> bool: ...
87+
) -> None: ...
8888

8989
SE = TypeVar(
9090
"SE",

asyncstdlib/itertools.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ class NoLock:
335335
async def __aenter__(self) -> None:
336336
pass
337337

338-
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool:
339-
return False
338+
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
339+
return None
340340

341341

342342
async def tee_peer(
@@ -460,9 +460,8 @@ def __iter__(self) -> Iterator[AnyIterable[T]]:
460460
async def __aenter__(self) -> "Tee[T]":
461461
return self
462462

463-
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool:
463+
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
464464
await self.aclose()
465-
return False
466465

467466
async def aclose(self) -> None:
468467
for child in self._children:

asyncstdlib/itertools.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class tee(Generic[T]):
132132
def __getitem__(self, item: slice) -> tuple[AsyncIterator[T], ...]: ...
133133
def __iter__(self) -> Iterator[AnyIterable[T]]: ...
134134
async def __aenter__(self: Self) -> Self: ...
135-
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ...
135+
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ...
136136
async def aclose(self) -> None: ...
137137

138138
def pairwise(iterable: AnyIterable[T]) -> AsyncIterator[tuple[T, T]]: ...

0 commit comments

Comments
 (0)