Skip to content

Commit

Permalink
Merge pull request #86 from bgreen-litl/python38
Browse files Browse the repository at this point in the history
Support python 3.8
  • Loading branch information
bgreen-litl authored Nov 16, 2019
2 parents 91d25b9 + a4d37d3 commit 10de5d3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dist/
.cache/
*.egg-info
poetry.lock
.vscode
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
matrix:
include:
- python: "3.5"
Expand All @@ -12,8 +13,9 @@ matrix:
env: PYTHONASYNCIODEBUG=x
- python: "3.7"
env: PYTHONASYNCIODEBUG=x
dist: xenial
sudo: true
- python: "3.8"
env: PYTHONASYNCIODEBUG=x

before_install:
- pip install poetry more-itertools
install:
Expand Down
2 changes: 1 addition & 1 deletion backoff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
'random_jitter'
]

__version__ = '1.8.1'
__version__ = '1.9.0'
8 changes: 5 additions & 3 deletions backoff/_async.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# coding:utf-8
import datetime
import functools
# Python 3.4 code and syntax is allowed in this module!
import asyncio
import asyncio # Python 3.5 code and syntax is allowed in this file
from datetime import timedelta

from backoff._common import (_init_wait_gen, _maybe_call, _next_wait)
Expand All @@ -12,7 +11,10 @@ def _ensure_coroutine(coro_or_func):
if asyncio.iscoroutinefunction(coro_or_func):
return coro_or_func
else:
return asyncio.coroutine(coro_or_func)
@functools.wraps(coro_or_func)
async def f(*args, **kwargs):
return coro_or_func(*args, **kwargs)
return f


def _ensure_coroutines(coros_or_funcs):
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "backoff"
version = "1.8.1"
version = "1.9.0"
description = "Function decoration for backoff and retry"
authors = ["Bob Green <[email protected]>"]
readme = "README.rst"
Expand All @@ -20,6 +20,7 @@ classifiers = ['Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Utilities']
Expand Down
34 changes: 19 additions & 15 deletions tests/python35/test_backoff_async.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# coding:utf-8

import asyncio
import asyncio # Python 3.5 code and syntax is allowed in this file
import backoff
import pytest
import random

from tests.common import _log_hdlrs, _save_target


async def _await_none(x):
return None


@pytest.mark.asyncio
async def test_on_predicate(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

@backoff.on_predicate(backoff.expo)
async def return_true(log, n):
Expand All @@ -26,7 +30,7 @@ async def return_true(log, n):

@pytest.mark.asyncio
async def test_on_predicate_max_tries(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

@backoff.on_predicate(backoff.expo, jitter=None, max_tries=3)
async def return_true(log, n):
Expand All @@ -42,7 +46,7 @@ async def return_true(log, n):

@pytest.mark.asyncio
async def test_on_exception(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

@backoff.on_exception(backoff.expo, KeyError)
async def keyerror_then_true(log, n):
Expand All @@ -59,7 +63,7 @@ async def keyerror_then_true(log, n):

@pytest.mark.asyncio
async def test_on_exception_tuple(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

@backoff.on_exception(backoff.expo, (KeyError, ValueError))
async def keyerror_valueerror_then_true(log):
Expand All @@ -81,7 +85,7 @@ async def keyerror_valueerror_then_true(log):

@pytest.mark.asyncio
async def test_on_exception_max_tries(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

@backoff.on_exception(backoff.expo, KeyError, jitter=None, max_tries=3)
async def keyerror_then_true(log, n, foo=None):
Expand All @@ -100,7 +104,7 @@ async def keyerror_then_true(log, n, foo=None):

@pytest.mark.asyncio
async def test_on_exception_constant_iterable(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

backoffs = []
giveups = []
Expand All @@ -127,7 +131,7 @@ async def endless_exceptions():

@pytest.mark.asyncio
async def test_on_exception_success_random_jitter(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

log, log_success, log_backoff, log_giveup = _log_hdlrs()

Expand Down Expand Up @@ -158,7 +162,7 @@ async def succeeder(*args, **kwargs):

@pytest.mark.asyncio
async def test_on_exception_success_full_jitter(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

log, log_success, log_backoff, log_giveup = _log_hdlrs()

Expand Down Expand Up @@ -265,7 +269,7 @@ async def exceptor(*args, **kwargs):

@pytest.mark.asyncio
async def test_on_exception_giveup_predicate(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

def on_baz(e):
return str(e) == "baz"
Expand All @@ -286,7 +290,7 @@ async def foo_bar_baz():

@pytest.mark.asyncio
async def test_on_exception_giveup_coro(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

async def on_baz(e):
return str(e) == "baz"
Expand Down Expand Up @@ -414,7 +418,7 @@ async def emptiness(*args, **kwargs):

@pytest.mark.asyncio
async def test_on_predicate_constant_iterable(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

waits = [1, 2, 3, 6, 9]
backoffs = []
Expand Down Expand Up @@ -446,7 +450,7 @@ async def falsey():
# on_predicate should support 0-argument jitter function.
@pytest.mark.asyncio
async def test_on_exception_success_0_arg_jitter(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)
monkeypatch.setattr('random.random', lambda: 0)

log, log_success, log_backoff, log_giveup = _log_hdlrs()
Expand Down Expand Up @@ -495,7 +499,7 @@ async def succeeder(*args, **kwargs):
# on_predicate should support 0-argument jitter function.
@pytest.mark.asyncio
async def test_on_predicate_success_0_arg_jitter(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)
monkeypatch.setattr('random.random', lambda: 0)

log, log_success, log_backoff, log_giveup = _log_hdlrs()
Expand Down Expand Up @@ -542,7 +546,7 @@ async def success(*args, **kwargs):

@pytest.mark.asyncio
async def test_on_exception_callable_max_tries(monkeypatch):
monkeypatch.setattr('asyncio.sleep', asyncio.coroutine(lambda x: None))
monkeypatch.setattr('asyncio.sleep', _await_none)

def lookup_max_tries():
return 3
Expand Down

0 comments on commit 10de5d3

Please sign in to comment.