diff --git a/aioredis/abc.py b/aioredis/abc.py index 0af13c65c..0c12783ae 100644 --- a/aioredis/abc.py +++ b/aioredis/abc.py @@ -5,8 +5,6 @@ import abc import asyncio -from abc import ABC - __all__ = [ 'AbcConnection', @@ -15,7 +13,7 @@ ] -class AbcConnection(ABC): +class AbcConnection(abc.ABC): """Abstract connection interface.""" @abc.abstractmethod @@ -84,7 +82,7 @@ class AbcPool(AbcConnection): """ @abc.abstractmethod - def get_connection(self): # TODO: arguments + def get_connection(self, command, args=()): """ Gets free connection from pool in a sync way. @@ -109,7 +107,7 @@ def address(self): """Connection address or None.""" -class AbcChannel(ABC): +class AbcChannel(abc.ABC): """Abstract Pub/Sub Channel interface.""" @property diff --git a/aioredis/locks.py b/aioredis/locks.py index 7a73e61d2..f8b93c3ce 100644 --- a/aioredis/locks.py +++ b/aioredis/locks.py @@ -2,7 +2,6 @@ import sys from asyncio.locks import Lock as _Lock -from asyncio import coroutine # Fixes an issue with all Python versions that leaves pending waiters # without being awakened when the first waiter is canceled. @@ -14,7 +13,7 @@ class Lock(_Lock): if sys.version_info < (3, 7, 0): - @coroutine + @asyncio.coroutine def acquire(self): """Acquire a lock. This method blocks until the lock is unlocked, then sets it to diff --git a/aioredis/pool.py b/aioredis/pool.py index ed6933107..2ada29f9e 100644 --- a/aioredis/pool.py +++ b/aioredis/pool.py @@ -282,8 +282,7 @@ async def select(self, db): async with self._cond: for i in range(self.freesize): res = res and (await self._pool[i].select(db)) - else: - self._db = db + self._db = db return res async def auth(self, password): diff --git a/aioredis/sentinel/pool.py b/aioredis/sentinel/pool.py index 819ef2117..d7996909b 100644 --- a/aioredis/sentinel/pool.py +++ b/aioredis/sentinel/pool.py @@ -83,7 +83,7 @@ def __init__(self, sentinels, *, db=None, password=None, ssl=None, async def echo_events(): try: while await monitor.wait_message(): - ch, (ev, data) = await monitor.get(encoding='utf-8') + _, (ev, data) = await monitor.get(encoding='utf-8') ev = ev.decode('utf-8') _logger.debug("%s: %s", ev, data) if ev in ('+odown',): @@ -295,8 +295,8 @@ async def discover_master(self, service, timeout): # TODO: clear (drop) connections to schedule reconnect await asyncio.sleep(idle_timeout, loop=self._loop) continue - else: - raise MasterNotFoundError("No master found for {}".format(service)) + # Otherwise + raise MasterNotFoundError("No master found for {}".format(service)) async def discover_slave(self, service, timeout, **kwargs): """Perform Slave discovery for specified service.""" @@ -358,8 +358,7 @@ async def _get_slave_address(self, sentinel, service): if {'s_down', 'o_down', 'disconnected'} & flags: continue return address - else: - raise BadState(state) # XXX: only last state + raise BadState() # XXX: only last state async def _verify_service_role(self, conn, role): res = await conn.execute(b'role', encoding='utf-8') diff --git a/setup.py b/setup.py index 10c2f777c..c03e8c97f 100644 --- a/setup.py +++ b/setup.py @@ -29,8 +29,7 @@ def read_version(): match = regexp.match(line) if match is not None: return match.group(1) - else: - raise RuntimeError('Cannot find version in aioredis/__init__.py') + raise RuntimeError('Cannot find version in {}'.format(init_py)) classifiers = [