Skip to content

Commit

Permalink
docs and test cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
CaselIT committed Jun 14, 2024
1 parent c68c169 commit 3026153
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 298 deletions.
10 changes: 5 additions & 5 deletions awaitlet/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def _safe_cancel_awaitable(awaitable: Awaitable[Any]) -> None:
def awaitlet(awaitable: Awaitable[_T]) -> _T:
"""Awaits an async function in a sync method.
The sync method must be inside a :func:`greenlet_spawn` context.
:func:`await_` calls cannot be nested.
The sync method must be inside a :func:`async_def` context.
:func:`awaitlet` calls cannot be nested.
:param awaitable: The coroutine to call.
Expand Down Expand Up @@ -95,7 +95,7 @@ async def async_def(
) -> _T:
"""Runs a sync function ``fn`` in a new greenlet.
The sync function can then use :func:`await_` to wait for async
The sync function can then use :func:`awaitlet` to wait for async
functions.
:param fn: The sync callable to call.
Expand All @@ -106,15 +106,15 @@ async def async_def(
result: Any
context = _AsyncIoGreenlet(fn, greenlet.getcurrent())
# runs the function synchronously in gl greenlet. If the execution
# is interrupted by await_, context is not dead and result is a
# is interrupted by awaitlet, context is not dead and result is a
# coroutine to wait. If the context is dead the function has
# returned, and its result can be returned.
switch_occurred = False
result = context.switch(*args, **kwargs)
while not context.dead:
switch_occurred = True
try:
# wait for a coroutine from await_ and then return its
# wait for a coroutine from awaitlet and then return its
# result back to it.
value = await result
except BaseException:
Expand Down
279 changes: 0 additions & 279 deletions awaitlet/util/langhelpers.py

This file was deleted.

13 changes: 4 additions & 9 deletions awaitlet/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing import TypeVar
from typing import Union

from .langhelpers import _pytest_fn_decorator
from .typing import Self

_T = TypeVar("_T", bound=Any)
Expand All @@ -25,9 +24,8 @@ def ne_(a, b, msg=None):
assert a != b, msg or "%r == %r" % (a, b)


def _run_coroutine_function(fn, *args, **kwargs):
runner = _Runner() # runner it lazy so it can be created here
return runner.run(fn(*args, **kwargs))
def run_coroutine_function(fn, *args, **kwargs):
return _runner.run(fn(*args, **kwargs))


class _Runner:
Expand Down Expand Up @@ -71,13 +69,10 @@ def _lazy_init(self) -> None:
self._loop = asyncio.new_event_loop()


def async_test(fn):
_runner = _Runner() # runner it lazy so it can be created here

@_pytest_fn_decorator
def decorate(fn, *args, **kwargs):
_run_coroutine_function(fn, *args, **kwargs)

return decorate(fn)
async_test: Any = None # assigned by conftest


class _ErrorContainer:
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["asyncio"]
license = {file = "LICENSE"}
requires-python = ">=3.8"
classifiers = [
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
Expand All @@ -21,7 +21,7 @@ classifiers = [
]

dependencies = [
"greenlet",
"greenlet >= 1",
"typing-extensions >= 4.6.0",
]

Expand All @@ -47,3 +47,6 @@ target-version = ['py38']
[tool.pytest.ini_options]
addopts = "--tb native -v -r sfxX -p warnings -p logging --strict-markers"
python_files = "tests/test_*.py"
markers = """
async_test: mark the given test as async
"""
Loading

0 comments on commit 3026153

Please sign in to comment.