Skip to content

Commit 49e3ee2

Browse files
Prepare release 3.10.0 (#60)
* added test for non-coroutine async * a.sync leaves ()->await T unchanged * docs dependency cleanup * docs typo fix * version bump
1 parent e26414d commit 49e3ee2

File tree

7 files changed

+31
-8
lines changed

7 files changed

+31
-8
lines changed

asyncstdlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
)
3636
from .asynctools import borrow, scoped_iter, await_each, apply, sync
3737

38-
__version__ = "3.9.2"
38+
__version__ = "3.10.0"
3939

4040
__all__ = [
4141
"anext",

asyncstdlib/asynctools.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,17 @@ async def compute_something_else() -> float:
326326
)
327327

328328

329+
@overload
330+
def sync(function: Callable[..., Awaitable[T]]) -> Callable[..., Awaitable[T]]:
331+
...
332+
333+
334+
@overload
329335
def sync(function: Callable[..., T]) -> Callable[..., Awaitable[T]]:
336+
...
337+
338+
339+
def sync(function: Callable) -> Callable[..., Awaitable[T]]:
330340
r"""
331341
Wraps a callable to ensure its result can be ``await``\ ed
332342
@@ -359,12 +369,13 @@ async def main():
359369
raise TypeError("function argument should be Callable")
360370

361371
if iscoroutinefunction(function):
362-
return function # type: ignore
372+
return function
363373

364374
@wraps(function)
365375
async def async_wrapped(*args, **kwargs):
366376
result = function(*args, **kwargs)
367-
377+
if isinstance(result, Awaitable):
378+
return await result
368379
return result
369380

370381
return async_wrapped

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
'sphinx.ext.imgmath',
5050
'sphinx.ext.viewcode',
5151
'sphinxcontrib_trio',
52-
'sphinxcontrib.contentui',
5352
]
5453

5554
# Add any paths that contain templates here, relative to this directory.

docs/source/api/asynctools.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ Iterator lifetime
2323
Async transforming
2424
==================
2525

26-
.. autofunction:: sync(function:(...) -> T) -> (...) -> await T
27-
:async:
26+
.. autofunction:: sync(function: (...) -> (await) T) -> (...) -> await T
2827

2928
.. versionadded:: 3.9.3
3029

docs/source/api/itertools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Iterator splitting
6161
:for: :(async iter T, ...)
6262

6363
.. autofunction:: pairwise(iterable: (async) iter T)
64-
:for: :(T, T)
64+
:async-for: :(T, T)
6565

6666
.. versionadded:: 3.10.0
6767

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test = [
2929
"pytest-cov",
3030
"mypy; implementation_name=='cpython'",
3131
]
32-
doc = ["sphinx", "sphinxcontrib-contentui", "sphinxcontrib-trio"]
32+
doc = ["sphinx", "sphinxcontrib-trio"]
3333

3434
[tool.flit.metadata.urls]
3535
Documentation = "https://asyncstdlib.readthedocs.io/en/latest/"

unittests/test_asynctools.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,17 @@ async def check_4(x: int, y: int, z: int) -> int:
221221
assert t1 == 110
222222
assert t2 == 120
223223
assert t3 == 125
224+
225+
226+
@sync
227+
async def test_sync_awaitable():
228+
"""Test any (…) -> await T is recognised"""
229+
230+
@a.sync
231+
def nocoro_async(value):
232+
async def coro():
233+
return value
234+
235+
return coro()
236+
237+
assert await nocoro_async(5) == 5

0 commit comments

Comments
 (0)