Blame 0000-Drop-support-for-Python-3.4-to-support-aiohttp-3.3.patch

13b151
From c5eb00d4151e204cab32a3026583326745054419 Mon Sep 17 00:00:00 2001
13b151
From: Stefan Tjarks <stefan.tjarks@eventbase.com>
13b151
Date: Tue, 17 Jul 2018 13:53:05 -0700
13b151
Subject: [PATCH] Drop support for Python 3.4 to support aiohttp>3.3
13b151
13b151
aiohttp dropped support for Python 3.4 and with it `asyncio.coroutine`
13b151
decorated generators.
13b151
To support latest aiohttp Python 3.4 support is dropped and all notion
13b151
of `asyncio.coroutine` is replaced with `async def`.
13b151
13b151
Signed-off-by: Randy Barlow <randy@electronsweatshop.com>
13b151
---
13b151
 .coveragerc-py34 => .coveragerc-py35          |   0
13b151
 .travis.yml                                   |   1 -
13b151
 Makefile                                      |  10 +-
13b151
 README.rst                                    |  17 +-
13b151
 backoff/_async.py                             |  33 ++--
13b151
 .../test_backoff_async.py                     | 167 +++++++-----------
13b151
 6 files changed, 84 insertions(+), 144 deletions(-)
13b151
 rename .coveragerc-py34 => .coveragerc-py35 (100%)
13b151
 rename tests/{python34 => python35}/test_backoff_async.py (82%)
13b151
13b151
diff --git a/.coveragerc-py34 b/.coveragerc-py35
13b151
similarity index 100%
13b151
rename from .coveragerc-py34
13b151
rename to .coveragerc-py35
13b151
diff --git a/.travis.yml b/.travis.yml
13b151
index 1c0c7fd..b5cb8de 100644
13b151
--- a/.travis.yml
13b151
+++ b/.travis.yml
13b151
@@ -2,7 +2,6 @@ language: python
13b151
 python:
13b151
   - "2.6"
13b151
   - "2.7"
13b151
-  - "3.4"
13b151
   - "3.5"
13b151
   - "3.6"
13b151
 matrix:
13b151
diff --git a/Makefile b/Makefile
13b151
index 66526bd..eb5f188 100644
13b151
--- a/Makefile
13b151
+++ b/Makefile
13b151
@@ -1,7 +1,7 @@
13b151
 PY_VERSION := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
13b151
 PY_MAJOR := $(word 1,${PY_VERSION})
13b151
 PY_MINOR := $(word 2,${PY_VERSION})
13b151
-PY_GTE_34 = $(shell echo $(PY_MAJOR).$(PY_MINOR)\>=3.4 | bc)
13b151
+PY_GTE_35 = $(shell echo $(PY_MAJOR).$(PY_MINOR)\>=3.5 | bc)
13b151
 PY_GTE_27 = $(shell echo $(PY_MAJOR).$(PY_MINOR)\>=2.7 | bc)
13b151
 
13b151
 
13b151
@@ -18,10 +18,10 @@ pep8:
13b151
 	@pep8 backoff tests
13b151
 
13b151
 flake8:
13b151
-ifeq ($(PY_GTE_34),1)
13b151
+ifeq ($(PY_GTE_35),1)
13b151
 	@flake8 backoff tests
13b151
 else ifeq ($(PY_GTE_27),1)
13b151
-	@flake8 --exclude tests/python34,backoff/_async.py backoff tests
13b151
+	@flake8 --exclude tests/python35,backoff/_async.py backoff tests
13b151
 else
13b151
 	@echo 'Not running flake8 for Python < 2.7'
13b151
 endif
13b151
@@ -32,8 +32,8 @@ clean:
13b151
 	@rm -rf build dist .coverage MANIFEST
13b151
 
13b151
 test: clean
13b151
-ifeq ($(PY_GTE_34),1)
13b151
-	@PYTHONPATH=. py.test --cov-config .coveragerc-py34 --cov backoff tests
13b151
+ifeq ($(PY_GTE_35),1)
13b151
+	@PYTHONPATH=. py.test --cov-config .coveragerc-py35 --cov backoff tests
13b151
 else
13b151
 	@PYTHONPATH=. py.test --cov-config .coveragerc-py2 --cov backoff tests/test_*.py
13b151
 endif
13b151
diff --git a/README.rst b/README.rst
13b151
index ee535e7..fee5723 100644
13b151
--- a/README.rst
13b151
+++ b/README.rst
13b151
@@ -284,22 +284,7 @@ On Python 3.5 and above with ``async def`` and ``await`` syntax:
13b151
             async with session.get(url) as response:
13b151
                 return await response.text()
13b151
 
13b151
-In case you use Python 3.4 you can use `@asyncio.coroutine` and `yield from`:
13b151
-
13b151
-.. code-block:: python
13b151
-
13b151
-    @backoff.on_exception(backoff.expo, aiohttp.ClientError, max_time=60)
13b151
-    @asyncio.coroutine
13b151
-    def get_url_py34(url):
13b151
-        with aiohttp.ClientSession() as session:
13b151
-            response = yield from session.get(url)
13b151
-            try:
13b151
-                return (yield from response.text())
13b151
-            except Exception:
13b151
-                response.close()
13b151
-                raise
13b151
-            finally:
13b151
-                yield from response.release()
13b151
+Python 3.4 is not supported.
13b151
 
13b151
 Logging configuration
13b151
 ---------------------
13b151
diff --git a/backoff/_async.py b/backoff/_async.py
13b151
index e1b70d0..2cd33a8 100644
13b151
--- a/backoff/_async.py
13b151
+++ b/backoff/_async.py
13b151
@@ -20,8 +20,7 @@ def _ensure_coroutines(coros_or_funcs):
13b151
     return [_ensure_coroutine(f) for f in coros_or_funcs]
13b151
 
13b151
 
13b151
-@asyncio.coroutine
13b151
-def _call_handlers(hdlrs, target, args, kwargs, tries, elapsed, **extra):
13b151
+async def _call_handlers(hdlrs, target, args, kwargs, tries, elapsed, **extra):
13b151
     details = {
13b151
         'target': target,
13b151
         'args': args,
13b151
@@ -31,7 +30,7 @@ def _call_handlers(hdlrs, target, args, kwargs, tries, elapsed, **extra):
13b151
     }
13b151
     details.update(extra)
13b151
     for hdlr in hdlrs:
13b151
-        yield from hdlr(details)
13b151
+        await hdlr(details)
13b151
 
13b151
 
13b151
 def retry_predicate(target, wait_gen, predicate,
13b151
@@ -49,8 +48,7 @@ def retry_predicate(target, wait_gen, predicate,
13b151
     assert asyncio.iscoroutinefunction(target)
13b151
 
13b151
     @functools.wraps(target)
13b151
-    @asyncio.coroutine
13b151
-    def retry(*args, **kwargs):
13b151
+    async def retry(*args, **kwargs):
13b151
 
13b151
         # change names because python 2.x doesn't have nonlocal
13b151
         max_tries_ = _maybe_call(max_tries)
13b151
@@ -64,20 +62,20 @@ def retry_predicate(target, wait_gen, predicate,
13b151
             elapsed = _total_seconds(datetime.datetime.now() - start)
13b151
             details = (target, args, kwargs, tries, elapsed)
13b151
 
13b151
-            ret = yield from target(*args, **kwargs)
13b151
+            ret = await target(*args, **kwargs)
13b151
             if predicate(ret):
13b151
                 max_tries_exceeded = (tries == max_tries_)
13b151
                 max_time_exceeded = (max_time_ is not None and
13b151
                                      elapsed >= max_time_)
13b151
 
13b151
                 if max_tries_exceeded or max_time_exceeded:
13b151
-                    yield from _call_handlers(
13b151
+                    await _call_handlers(
13b151
                         giveup_hdlrs, *details, value=ret)
13b151
                     break
13b151
 
13b151
                 seconds = _next_wait(wait, jitter, elapsed, max_time_)
13b151
 
13b151
-                yield from _call_handlers(
13b151
+                await _call_handlers(
13b151
                     backoff_hdlrs, *details, value=ret, wait=seconds)
13b151
 
13b151
                 # Note: there is no convenient way to pass explicit event
13b151
@@ -89,10 +87,10 @@ def retry_predicate(target, wait_gen, predicate,
13b151
                 # See for details:
13b151
                 #   <https://groups.google.com/forum/#!topic/python-tulip/yF9C-rFpiKk>
13b151
                 #   <https://bugs.python.org/issue28613>
13b151
-                yield from asyncio.sleep(seconds)
13b151
+                await asyncio.sleep(seconds)
13b151
                 continue
13b151
             else:
13b151
-                yield from _call_handlers(success_hdlrs, *details, value=ret)
13b151
+                await _call_handlers(success_hdlrs, *details, value=ret)
13b151
                 break
13b151
 
13b151
         return ret
13b151
@@ -114,8 +112,7 @@ def retry_exception(target, wait_gen, exception,
13b151
     assert not asyncio.iscoroutinefunction(jitter)
13b151
 
13b151
     @functools.wraps(target)
13b151
-    @asyncio.coroutine
13b151
-    def retry(*args, **kwargs):
13b151
+    async def retry(*args, **kwargs):
13b151
         # change names because python 2.x doesn't have nonlocal
13b151
         max_tries_ = _maybe_call(max_tries)
13b151
         max_time_ = _maybe_call(max_time)
13b151
@@ -129,20 +126,20 @@ def retry_exception(target, wait_gen, exception,
13b151
             details = (target, args, kwargs, tries, elapsed)
13b151
 
13b151
             try:
13b151
-                ret = yield from target(*args, **kwargs)
13b151
+                ret = await target(*args, **kwargs)
13b151
             except exception as e:
13b151
-                giveup_result = yield from giveup(e)
13b151
+                giveup_result = await giveup(e)
13b151
                 max_tries_exceeded = (tries == max_tries_)
13b151
                 max_time_exceeded = (max_time_ is not None and
13b151
                                      elapsed >= max_time_)
13b151
 
13b151
                 if giveup_result or max_tries_exceeded or max_time_exceeded:
13b151
-                    yield from _call_handlers(giveup_hdlrs, *details)
13b151
+                    await _call_handlers(giveup_hdlrs, *details)
13b151
                     raise
13b151
 
13b151
                 seconds = _next_wait(wait, jitter, elapsed, max_time_)
13b151
 
13b151
-                yield from _call_handlers(
13b151
+                await _call_handlers(
13b151
                     backoff_hdlrs, *details, wait=seconds)
13b151
 
13b151
                 # Note: there is no convenient way to pass explicit event
13b151
@@ -154,9 +151,9 @@ def retry_exception(target, wait_gen, exception,
13b151
                 # See for details:
13b151
                 #   <https://groups.google.com/forum/#!topic/python-tulip/yF9C-rFpiKk>
13b151
                 #   <https://bugs.python.org/issue28613>
13b151
-                yield from asyncio.sleep(seconds)
13b151
+                await asyncio.sleep(seconds)
13b151
             else:
13b151
-                yield from _call_handlers(success_hdlrs, *details)
13b151
+                await _call_handlers(success_hdlrs, *details)
13b151
 
13b151
                 return ret
13b151
     return retry
13b151
diff --git a/tests/python34/test_backoff_async.py b/tests/python35/test_backoff_async.py
13b151
similarity index 82%
13b151
rename from tests/python34/test_backoff_async.py
13b151
rename to tests/python35/test_backoff_async.py
13b151
index 0917c6b..c1a30f8 100644
13b151
--- a/tests/python34/test_backoff_async.py
13b151
+++ b/tests/python35/test_backoff_async.py
13b151
@@ -8,47 +8,41 @@ import random
13b151
 from tests.common import _log_hdlrs, _save_target
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_predicate(monkeypatch):
13b151
+async def test_on_predicate(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
 
13b151
     @backoff.on_predicate(backoff.expo)
13b151
-    @asyncio.coroutine
13b151
-    def return_true(log, n):
13b151
+    async def return_true(log, n):
13b151
         val = (len(log) == n - 1)
13b151
         log.append(val)
13b151
         return val
13b151
 
13b151
     log = []
13b151
-    ret = yield from return_true(log, 3)
13b151
+    ret = await return_true(log, 3)
13b151
     assert ret is True
13b151
     assert 3 == len(log)
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_predicate_max_tries(monkeypatch):
13b151
+async def test_on_predicate_max_tries(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
 
13b151
     @backoff.on_predicate(backoff.expo, jitter=None, max_tries=3)
13b151
-    @asyncio.coroutine
13b151
-    def return_true(log, n):
13b151
+    async def return_true(log, n):
13b151
         val = (len(log) == n)
13b151
         log.append(val)
13b151
         return val
13b151
 
13b151
     log = []
13b151
-    ret = yield from return_true(log, 10)
13b151
+    ret = await return_true(log, 10)
13b151
     assert ret is False
13b151
     assert 3 == len(log)
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception(monkeypatch):
13b151
+async def test_on_exception(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
 
13b151
     @backoff.on_exception(backoff.expo, KeyError)
13b151
-    @asyncio.coroutine
13b151
-    def keyerror_then_true(log, n):
13b151
+    async def keyerror_then_true(log, n):
13b151
         if len(log) == n:
13b151
             return True
13b151
         e = KeyError()
13b151
@@ -56,17 +50,15 @@ def test_on_exception(monkeypatch):
13b151
         raise e
13b151
 
13b151
     log = []
13b151
-    assert (yield from keyerror_then_true(log, 3)) is True
13b151
+    assert (await keyerror_then_true(log, 3)) is True
13b151
     assert 3 == len(log)
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_tuple(monkeypatch):
13b151
+async def test_on_exception_tuple(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
 
13b151
     @backoff.on_exception(backoff.expo, (KeyError, ValueError))
13b151
-    @asyncio.coroutine
13b151
-    def keyerror_valueerror_then_true(log):
13b151
+    async def keyerror_valueerror_then_true(log):
13b151
         if len(log) == 2:
13b151
             return True
13b151
         if len(log) == 0:
13b151
@@ -77,19 +69,17 @@ def test_on_exception_tuple(monkeypatch):
13b151
         raise e
13b151
 
13b151
     log = []
13b151
-    assert (yield from keyerror_valueerror_then_true(log)) is True
13b151
+    assert (await keyerror_valueerror_then_true(log)) is True
13b151
     assert 2 == len(log)
13b151
     assert isinstance(log[0], KeyError)
13b151
     assert isinstance(log[1], ValueError)
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_max_tries(monkeypatch):
13b151
+async def test_on_exception_max_tries(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
 
13b151
     @backoff.on_exception(backoff.expo, KeyError, jitter=None, max_tries=3)
13b151
-    @asyncio.coroutine
13b151
-    def keyerror_then_true(log, n, foo=None):
13b151
+    async def keyerror_then_true(log, n, foo=None):
13b151
         if len(log) == n:
13b151
             return True
13b151
         e = KeyError()
13b151
@@ -98,13 +88,12 @@ def test_on_exception_max_tries(monkeypatch):
13b151
 
13b151
     log = []
13b151
     with pytest.raises(KeyError):
13b151
-        yield from keyerror_then_true(log, 10, foo="bar")
13b151
+        await keyerror_then_true(log, 10, foo="bar")
13b151
 
13b151
     assert 3 == len(log)
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_success_random_jitter(monkeypatch):
13b151
+async def test_on_exception_success_random_jitter(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
 
13b151
     log, log_success, log_backoff, log_giveup = _log_hdlrs()
13b151
@@ -117,13 +106,12 @@ def test_on_exception_success_random_jitter(monkeypatch):
13b151
                           jitter=backoff.random_jitter,
13b151
                           factor=0.5)
13b151
     @_save_target
13b151
-    @asyncio.coroutine
13b151
-    def succeeder(*args, **kwargs):
13b151
+    async def succeeder(*args, **kwargs):
13b151
         # succeed after we've backed off twice
13b151
         if len(log['backoff']) < 2:
13b151
             raise ValueError("catch me")
13b151
 
13b151
-    yield from succeeder(1, 2, 3, foo=1, bar=2)
13b151
+    await succeeder(1, 2, 3, foo=1, bar=2)
13b151
 
13b151
     # we try 3 times, backing off twice before succeeding
13b151
     assert len(log['success']) == 1
13b151
@@ -135,8 +123,7 @@ def test_on_exception_success_random_jitter(monkeypatch):
13b151
         assert details['wait'] >= 0.5 * 2 ** i
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_success_full_jitter(monkeypatch):
13b151
+async def test_on_exception_success_full_jitter(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
 
13b151
     log, log_success, log_backoff, log_giveup = _log_hdlrs()
13b151
@@ -149,13 +136,12 @@ def test_on_exception_success_full_jitter(monkeypatch):
13b151
                           jitter=backoff.full_jitter,
13b151
                           factor=0.5)
13b151
     @_save_target
13b151
-    @asyncio.coroutine
13b151
-    def succeeder(*args, **kwargs):
13b151
+    async def succeeder(*args, **kwargs):
13b151
         # succeed after we've backed off twice
13b151
         if len(log['backoff']) < 2:
13b151
             raise ValueError("catch me")
13b151
 
13b151
-    yield from succeeder(1, 2, 3, foo=1, bar=2)
13b151
+    await succeeder(1, 2, 3, foo=1, bar=2)
13b151
 
13b151
     # we try 3 times, backing off twice before succeeding
13b151
     assert len(log['success']) == 1
13b151
@@ -167,8 +153,7 @@ def test_on_exception_success_full_jitter(monkeypatch):
13b151
         assert details['wait'] <= 0.5 * 2 ** i
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_success():
13b151
+async def test_on_exception_success():
13b151
     log, log_success, log_backoff, log_giveup = _log_hdlrs()
13b151
 
13b151
     @backoff.on_exception(backoff.constant,
13b151
@@ -179,13 +164,12 @@ def test_on_exception_success():
13b151
                           jitter=lambda: 0,
13b151
                           interval=0)
13b151
     @_save_target
13b151
-    @asyncio.coroutine
13b151
     def succeeder(*args, **kwargs):
13b151
         # succeed after we've backed off twice
13b151
         if len(log['backoff']) < 2:
13b151
             raise ValueError("catch me")
13b151
 
13b151
-    yield from succeeder(1, 2, 3, foo=1, bar=2)
13b151
+    await succeeder(1, 2, 3, foo=1, bar=2)
13b151
 
13b151
     # we try 3 times, backing off twice before succeeding
13b151
     assert len(log['success']) == 1
13b151
@@ -211,8 +195,7 @@ def test_on_exception_success():
13b151
                        'tries': 3}
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_giveup():
13b151
+async def test_on_exception_giveup():
13b151
     log, log_success, log_backoff, log_giveup = _log_hdlrs()
13b151
 
13b151
     @backoff.on_exception(backoff.constant,
13b151
@@ -224,12 +207,11 @@ def test_on_exception_giveup():
13b151
                           jitter=lambda: 0,
13b151
                           interval=0)
13b151
     @_save_target
13b151
-    @asyncio.coroutine
13b151
-    def exceptor(*args, **kwargs):
13b151
+    async def exceptor(*args, **kwargs):
13b151
         raise ValueError("catch me")
13b151
 
13b151
     with pytest.raises(ValueError):
13b151
-        yield from exceptor(1, 2, 3, foo=1, bar=2)
13b151
+        await exceptor(1, 2, 3, foo=1, bar=2)
13b151
 
13b151
     # we try 3 times, backing off twice and giving up once
13b151
     assert len(log['success']) == 0
13b151
@@ -245,8 +227,7 @@ def test_on_exception_giveup():
13b151
                        'tries': 3}
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_giveup_predicate(monkeypatch):
13b151
+async def test_on_exception_giveup_predicate(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
 
13b151
     def on_baz(e):
13b151
@@ -257,22 +238,19 @@ def test_on_exception_giveup_predicate(monkeypatch):
13b151
     @backoff.on_exception(backoff.constant,
13b151
                           ValueError,
13b151
                           giveup=on_baz)
13b151
-    @asyncio.coroutine
13b151
-    def foo_bar_baz():
13b151
+    async def foo_bar_baz():
13b151
         raise ValueError(vals.pop())
13b151
 
13b151
     with pytest.raises(ValueError):
13b151
-        yield from foo_bar_baz()
13b151
+        await foo_bar_baz()
13b151
 
13b151
     assert not vals
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_giveup_coro(monkeypatch):
13b151
+async def test_on_exception_giveup_coro(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
 
13b151
-    @asyncio.coroutine
13b151
-    def on_baz(e):
13b151
+    async def on_baz(e):
13b151
         return str(e) == "baz"
13b151
 
13b151
     vals = ["baz", "bar", "foo"]
13b151
@@ -280,18 +258,16 @@ def test_on_exception_giveup_coro(monkeypatch):
13b151
     @backoff.on_exception(backoff.constant,
13b151
                           ValueError,
13b151
                           giveup=on_baz)
13b151
-    @asyncio.coroutine
13b151
-    def foo_bar_baz():
13b151
+    async def foo_bar_baz():
13b151
         raise ValueError(vals.pop())
13b151
 
13b151
     with pytest.raises(ValueError):
13b151
-        yield from foo_bar_baz()
13b151
+        await foo_bar_baz()
13b151
 
13b151
     assert not vals
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_predicate_success():
13b151
+async def test_on_predicate_success():
13b151
     log, log_success, log_backoff, log_giveup = _log_hdlrs()
13b151
 
13b151
     @backoff.on_predicate(backoff.constant,
13b151
@@ -301,12 +277,11 @@ def test_on_predicate_success():
13b151
                           jitter=lambda: 0,
13b151
                           interval=0)
13b151
     @_save_target
13b151
-    @asyncio.coroutine
13b151
-    def success(*args, **kwargs):
13b151
+    async def success(*args, **kwargs):
13b151
         # succeed after we've backed off twice
13b151
         return len(log['backoff']) == 2
13b151
 
13b151
-    yield from success(1, 2, 3, foo=1, bar=2)
13b151
+    await success(1, 2, 3, foo=1, bar=2)
13b151
 
13b151
     # we try 3 times, backing off twice before succeeding
13b151
     assert len(log['success']) == 1
13b151
@@ -334,8 +309,7 @@ def test_on_predicate_success():
13b151
                        'value': True}
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_predicate_giveup():
13b151
+async def test_on_predicate_giveup():
13b151
     log, log_success, log_backoff, log_giveup = _log_hdlrs()
13b151
 
13b151
     @backoff.on_predicate(backoff.constant,
13b151
@@ -346,11 +320,10 @@ def test_on_predicate_giveup():
13b151
                           jitter=lambda: 0,
13b151
                           interval=0)
13b151
     @_save_target
13b151
-    @asyncio.coroutine
13b151
-    def emptiness(*args, **kwargs):
13b151
+    async def emptiness(*args, **kwargs):
13b151
         pass
13b151
 
13b151
-    yield from emptiness(1, 2, 3, foo=1, bar=2)
13b151
+    await emptiness(1, 2, 3, foo=1, bar=2)
13b151
 
13b151
     # we try 3 times, backing off twice and giving up once
13b151
     assert len(log['success']) == 0
13b151
@@ -367,8 +340,7 @@ def test_on_predicate_giveup():
13b151
                        'value': None}
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_predicate_iterable_handlers():
13b151
+async def test_on_predicate_iterable_handlers():
13b151
     hdlrs = [_log_hdlrs() for _ in range(3)]
13b151
 
13b151
     @backoff.on_predicate(backoff.constant,
13b151
@@ -379,11 +351,10 @@ def test_on_predicate_iterable_handlers():
13b151
                           jitter=lambda: 0,
13b151
                           interval=0)
13b151
     @_save_target
13b151
-    @asyncio.coroutine
13b151
-    def emptiness(*args, **kwargs):
13b151
+    async def emptiness(*args, **kwargs):
13b151
         pass
13b151
 
13b151
-    yield from emptiness(1, 2, 3, foo=1, bar=2)
13b151
+    await emptiness(1, 2, 3, foo=1, bar=2)
13b151
 
13b151
     for i in range(3):
13b151
         assert len(hdlrs[i][0]['success']) == 0
13b151
@@ -402,8 +373,7 @@ def test_on_predicate_iterable_handlers():
13b151
 
13b151
 # To maintain backward compatibility,
13b151
 # on_predicate should support 0-argument jitter function.
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_success_0_arg_jitter(monkeypatch):
13b151
+async def test_on_exception_success_0_arg_jitter(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
     monkeypatch.setattr('random.random', lambda: 0)
13b151
 
13b151
@@ -417,13 +387,12 @@ def test_on_exception_success_0_arg_jitter(monkeypatch):
13b151
                           jitter=random.random,
13b151
                           interval=0)
13b151
     @_save_target
13b151
-    @asyncio.coroutine
13b151
-    def succeeder(*args, **kwargs):
13b151
+    async def succeeder(*args, **kwargs):
13b151
         # succeed after we've backed off twice
13b151
         if len(log['backoff']) < 2:
13b151
             raise ValueError("catch me")
13b151
 
13b151
-    yield from succeeder(1, 2, 3, foo=1, bar=2)
13b151
+    await succeeder(1, 2, 3, foo=1, bar=2)
13b151
 
13b151
     # we try 3 times, backing off twice before succeeding
13b151
     assert len(log['success']) == 1
13b151
@@ -451,8 +420,7 @@ def test_on_exception_success_0_arg_jitter(monkeypatch):
13b151
 
13b151
 # To maintain backward compatibility,
13b151
 # on_predicate should support 0-argument jitter function.
13b151
-@pytest.mark.asyncio
13b151
-def test_on_predicate_success_0_arg_jitter(monkeypatch):
13b151
+async def test_on_predicate_success_0_arg_jitter(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
     monkeypatch.setattr('random.random', lambda: 0)
13b151
 
13b151
@@ -465,12 +433,11 @@ def test_on_predicate_success_0_arg_jitter(monkeypatch):
13b151
                           jitter=random.random,
13b151
                           interval=0)
13b151
     @_save_target
13b151
-    @asyncio.coroutine
13b151
-    def success(*args, **kwargs):
13b151
+    async def success(*args, **kwargs):
13b151
         # succeed after we've backed off twice
13b151
         return len(log['backoff']) == 2
13b151
 
13b151
-    yield from success(1, 2, 3, foo=1, bar=2)
13b151
+    await success(1, 2, 3, foo=1, bar=2)
13b151
 
13b151
     # we try 3 times, backing off twice before succeeding
13b151
     assert len(log['success']) == 1
13b151
@@ -498,8 +465,7 @@ def test_on_predicate_success_0_arg_jitter(monkeypatch):
13b151
                        'value': True}
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_callable_max_tries(monkeypatch):
13b151
+async def test_on_exception_callable_max_tries(monkeypatch):
13b151
     monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
13b151
 
13b151
     def lookup_max_tries():
13b151
@@ -510,19 +476,17 @@ def test_on_exception_callable_max_tries(monkeypatch):
13b151
     @backoff.on_exception(backoff.constant,
13b151
                           ValueError,
13b151
                           max_tries=lookup_max_tries)
13b151
-    @asyncio.coroutine
13b151
-    def exceptor():
13b151
+    async def exceptor():
13b151
         log.append(True)
13b151
         raise ValueError()
13b151
 
13b151
     with pytest.raises(ValueError):
13b151
-        yield from exceptor()
13b151
+        await exceptor()
13b151
 
13b151
     assert len(log) == 3
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_callable_gen_kwargs():
13b151
+async def test_on_exception_callable_gen_kwargs():
13b151
 
13b151
     def lookup_foo():
13b151
         return "foo"
13b151
@@ -539,25 +503,22 @@ def test_on_exception_callable_gen_kwargs():
13b151
                           max_tries=2,
13b151
                           foo=lookup_foo,
13b151
                           bar="bar")
13b151
-    @asyncio.coroutine
13b151
-    def exceptor():
13b151
+    async def exceptor():
13b151
         raise ValueError("aah")
13b151
 
13b151
     with pytest.raises(ValueError):
13b151
-        yield from exceptor()
13b151
+        await exceptor()
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_coro_cancelling(event_loop):
13b151
+async def test_on_exception_coro_cancelling(event_loop):
13b151
     sleep_started_event = asyncio.Event()
13b151
 
13b151
     @backoff.on_predicate(backoff.expo)
13b151
-    @asyncio.coroutine
13b151
-    def coro():
13b151
+    async def coro():
13b151
         sleep_started_event.set()
13b151
 
13b151
         try:
13b151
-            yield from asyncio.sleep(10)
13b151
+            await asyncio.sleep(10)
13b151
         except asyncio.CancelledError:
13b151
             return True
13b151
 
13b151
@@ -565,17 +526,16 @@ def test_on_exception_coro_cancelling(event_loop):
13b151
 
13b151
     task = event_loop.create_task(coro())
13b151
 
13b151
-    yield from sleep_started_event.wait()
13b151
+    await sleep_started_event.wait()
13b151
 
13b151
     task.cancel()
13b151
 
13b151
-    assert (yield from task)
13b151
+    assert (await task)
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_exception_on_regular_function():
13b151
+async def test_on_exception_on_regular_function():
13b151
     # Force this function to be a running coroutine.
13b151
-    yield from asyncio.sleep(0)
13b151
+    await asyncio.sleep(0)
13b151
 
13b151
     with pytest.raises(TypeError) as excinfo:
13b151
         @backoff.on_exception(backoff.expo, ValueError)
13b151
@@ -584,10 +544,9 @@ def test_on_exception_on_regular_function():
13b151
     assert "applied to a regular function" in str(excinfo.value)
13b151
 
13b151
 
13b151
-@pytest.mark.asyncio
13b151
-def test_on_predicate_on_regular_function():
13b151
+async def test_on_predicate_on_regular_function():
13b151
     # Force this function to be a running coroutine.
13b151
-    yield from asyncio.sleep(0)
13b151
+    await asyncio.sleep(0)
13b151
 
13b151
     with pytest.raises(TypeError) as excinfo:
13b151
         @backoff.on_predicate(backoff.expo)
13b151
-- 
13b151
2.18.0
13b151