Skip to content

Commit

Permalink
Merge pull request #316 from eric-weaver/issue-303-conditionally-use-…
Browse files Browse the repository at this point in the history
…async-def

Use async def for python > 3.5
  • Loading branch information
spulec committed Oct 31, 2019
2 parents 2733b08 + 33f13dc commit a8225d3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 3 additions & 4 deletions freezegun/_async.py
Expand Up @@ -5,13 +5,12 @@

def wrap_coroutine(api, coroutine):
@functools.wraps(coroutine)
@asyncio.coroutine
def wrapper(*args, **kwargs):
async def wrapper(*args, **kwargs):
with api as time_factory:
if api.as_arg:
result = yield from coroutine(time_factory, *args, **kwargs)
result = await coroutine(time_factory, *args, **kwargs)
else:
result = yield from coroutine(*args, **kwargs)
result = await coroutine(*args, **kwargs)
return result

return wrapper
17 changes: 17 additions & 0 deletions freezegun/_async_coroutine.py
@@ -0,0 +1,17 @@
import functools

import asyncio


def wrap_coroutine(api, coroutine):
@functools.wraps(coroutine)
@asyncio.coroutine
def wrapper(*args, **kwargs):
with api as time_factory:
if api.as_arg:
result = yield from coroutine(time_factory, *args, **kwargs)
else:
result = yield from coroutine(*args, **kwargs)
return result

return wrapper
5 changes: 4 additions & 1 deletion freezegun/api.py
Expand Up @@ -79,7 +79,10 @@

try:
iscoroutinefunction = inspect.iscoroutinefunction
from freezegun._async import wrap_coroutine
if sys.version_info < (3, 5):
from freezegun._async_coroutine import wrap_coroutine
else:
from freezegun._async import wrap_coroutine
except AttributeError:
iscoroutinefunction = lambda x: False

Expand Down

0 comments on commit a8225d3

Please sign in to comment.