Skip to content

Commit

Permalink
Update async generators protocol for Python 3.5.2+ (fixes aio-libs#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
beezz committed Sep 2, 2016
1 parent a48542b commit c6da6bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 4 additions & 2 deletions aiopg/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import psycopg2

from .log import logger
from .utils import PY_35
from .utils import PY_35, PY_352


class Cursor:
Expand Down Expand Up @@ -379,10 +379,12 @@ def __iter__(self):

if PY_35: # pragma: no branch

@asyncio.coroutine
def __aiter__(self):
return self

if not PY_352:
__aiter__ = asyncio.coroutine(__aiter__)

@asyncio.coroutine
def __anext__(self):
ret = yield from self.fetchone()
Expand Down
7 changes: 5 additions & 2 deletions aiopg/sa/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from sqlalchemy.sql import expression, sqltypes

from ..utils import PY_35
from ..utils import PY_35, PY_352
from . import exc


Expand Down Expand Up @@ -324,10 +324,13 @@ def __iter__(self):
yield row

if PY_35: # pragma: no branch
@asyncio.coroutine

def __aiter__(self):
return self

if not PY_352:
__aiter__ = asyncio.coroutine(__aiter__)

@asyncio.coroutine
def __anext__(self):
ret = yield from self.fetchone()
Expand Down
14 changes: 10 additions & 4 deletions aiopg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@


PY_35 = sys.version_info >= (3, 5)
PY_352 = sys.version_info >= (3, 5, 2)

if PY_35:
from collections.abc import Coroutine
base = Coroutine
Expand Down Expand Up @@ -84,10 +86,14 @@ def __aexit__(self, exc_type, exc, tb):
class _SAConnectionContextManager(_ContextManager):

if PY_35: # pragma: no branch
@asyncio.coroutine
def __aiter__(self):
result = yield from self._coro
return result
if PY_352:
def __aiter__(self):
return self._coro
else:
@asyncio.coroutine
def __aiter__(self):
result = yield from self._coro
return result


class _PoolContextManager(_ContextManager):
Expand Down

0 comments on commit c6da6bd

Please sign in to comment.