Skip to content

Commit e82e753

Browse files
Merge pull request #153 from maxfischer2781/maintenance/test_loop
Maintenance for Test Loop
2 parents 961c857 + ad71cc9 commit e82e753

File tree

13 files changed

+119
-82
lines changed

13 files changed

+119
-82
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 - 2020 Max Fischer
3+
Copyright (c) 2019 - 2024 Max Fischer
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

asyncstdlib/asynctools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class _BorrowedAsyncIterator(AsyncGenerator[T, S]):
3535
__slots__ = "__wrapped__", "__anext__", "asend", "athrow", "_wrapper"
3636

3737
# Type checker does not understand `__slot__` definitions
38-
__anext__: Callable[[Any], Awaitable[T]]
38+
__anext__: Callable[[Any], Coroutine[Any, Any, T]]
3939
asend: Any
4040
athrow: Any
4141

asyncstdlib/contextlib.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,15 @@ def push(self, exit: SE) -> SE:
328328
If a context manager must also be entered, use :py:meth:`~.enter_context`
329329
instead.
330330
"""
331-
try:
331+
aexit: Callable[..., Awaitable[Union[None, bool]]]
332+
if hasattr(exit, "__aexit__"):
332333
aexit = exit.__aexit__ # type: ignore
333-
except AttributeError:
334-
try:
335-
aexit = awaitify(
336-
exit.__exit__, # type: ignore
337-
)
338-
except AttributeError:
339-
assert callable(
340-
exit
341-
), f"Expected (async) context manager or callable, got {exit}"
342-
aexit = awaitify(exit)
334+
elif hasattr(exit, "__exit__"):
335+
aexit = awaitify(exit.__exit__) # type: ignore
336+
elif callable(exit):
337+
aexit = awaitify(exit) # type: ignore
338+
else:
339+
raise TypeError(f"Expected (async) context manager or callable, got {exit}")
343340
self._exit_callbacks.append(aexit) # pyright: ignore[reportUnknownArgumentType]
344341
return exit
345342

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
project = "asyncstdlib"
2828
author = "Max Fischer"
29-
copyright = f"2019 {author}"
29+
copyright = f"2019-2024 {author}"
3030

3131
# The short X.Y version
3232
version = __version__

docs/index.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ The missing ``async`` toolbox
5656
:caption: Development & Maintenance
5757
:hidden:
5858

59-
source/contributing
60-
source/publishing
59+
source/devel/contributing
60+
source/devel/testloop
61+
source/devel/publishing
6162

6263
The ``asyncstdlib`` library re-implements functions and classes of the Python
6364
standard library to make them compatible with ``async`` callables, iterables

docs/source/api/contextlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Context Managers
1616
An :term:`abstract base class` for asynchronous context managers
1717

1818
This class can be used to check whether some object is an
19-
asynchronous context manager. If a class may inherit from
19+
asynchronous context manager. A class may inherit from
2020
``AbstractContextManager``, in which case it must implement
2121
an ``__aenter__`` method; the default ``__aenter__`` returns
2222
the asynchronous context manager itself.
File renamed without changes.
File renamed without changes.

docs/source/devel/testloop.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
===============
2+
Test Event Loop
3+
===============
4+
5+
.. py:module:: unittests.utility
6+
:synopsis: testing utilities
7+
8+
To facilitate event loop agnostic features, :py:mod:`asyncstdlib` includes
9+
its own custom event loop implementation for testing.
10+
This is provided as a simple decorator that is compatible with :py:mod:`pytest`,
11+
as well as a number of `async` commands specific to the event loop.
12+
13+
Event Loops
14+
===========
15+
16+
The test event loop is available via a decorator that should be directly applied
17+
to an ``async def`` test case.
18+
19+
.. autofunction:: sync(test_case: (...) -> (await) None) -> (...) -> None
20+
21+
Async commands
22+
==============
23+
24+
.. autoclass:: Schedule(*await Any)
25+
26+
.. py:class:: Switch(skip: int, /)
27+
:no-index:
28+
29+
.. py:class:: Switch(min: int, max: int, /)
30+
:no-index:
31+
32+
.. autoclass:: Switch()
33+
34+
.. autoclass:: Lock

unittests/test_builtins.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import asyncstdlib as a
66

7-
from .utility import sync, asyncify, awaitify, inside_loop
7+
from .utility import sync, asyncify, awaitify
88

99

1010
def hide_coroutine(corofunc):
@@ -83,8 +83,7 @@ async def __aiter__(self):
8383
yield 1
8484
finally:
8585
nonlocal closed
86-
if await inside_loop():
87-
closed = True
86+
closed = True
8887

8988
zip_iter = a.zip(asyncify(range(-5, 0)), SomeIterable())
9089
async for va, vb in zip_iter:

0 commit comments

Comments
 (0)