Skip to content

Commit 89c95e3

Browse files
smagafurovvir-mir
authored andcommitted
python3.7 support (#437)
* python3.7 support * do not test with python nightly * add python nightly (now 3.7-dev) testing * add forgotten @asyncio.coroutine decorator * tambourine dances trying to prevent lower tests coverage * python3.7: __aiter__ MUST return object that implement __anext__ * use psycopg2.connect `async_` kwarg * Await result before first async iteration in 3.5.2+ in SQL alchemy execute. Supplements pull request #437 for #436. * Fix for RuntimeError in Python 3.7+ from unexpected StopIteration raise. The behavior of iteration has changed to where a StopIteration exception should not be raised inside a generator except by something unexpected. * Allow QA of StopAsyncIteration lines, give flake8 built-in hint in <3.5 Resolves Python 3.4 flake8 continuous integration failure. * bare StopAsyncIteration breaks code coverage in python 3.4 * Revert "bare StopAsyncIteration breaks code coverage in python 3.4" This reverts commit 8d82522. * Add proper job for 3.7 * Add 3.7 job w/o debug
1 parent 9d8bae5 commit 89c95e3

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,22 @@ python:
99
- "3.4"
1010
- "3.5"
1111
- "3.6"
12+
- "nightly"
13+
14+
.mixtures:
15+
- &py3_7-base
16+
python: "3.7"
17+
dist: xenial
18+
sudo: required
19+
jobs:
20+
include:
21+
- <<: *py3_7-base
22+
23+
- <<: *py3_7-base
24+
env:
1225

1326
install:
27+
- pip install -U setuptools
1428
- python setup.py install
1529
- pip install -Ur requirements.txt
1630
- pip install codecov

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pep:
88
pep8 aiopg examples tests
99

1010
flake:
11-
extra=$$(python -c "import sys;sys.stdout.write('--exclude tests/pep492') if sys.version_info[:3] < (3, 5, 0) else sys.stdout.write('examples')"); \
11+
extra=$$(python -c "import sys;sys.stdout.write('--exclude tests/pep492 --builtins=StopAsyncIteration') if sys.version_info[:3] < (3, 5, 0) else sys.stdout.write('examples')"); \
1212
flake8 aiopg tests $$extra
1313

1414
test: flake

aiopg/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Connection:
106106

107107
def __init__(self, dsn, loop, timeout, waiter, echo, **kwargs):
108108
self._loop = loop
109-
self._conn = psycopg2.connect(dsn, async=True, **kwargs)
109+
self._conn = psycopg2.connect(dsn, async_=True, **kwargs)
110110
self._dsn = self._conn.dsn
111111
assert self._conn.isexecuting(), "Is conn an async at all???"
112112
self._fileno = self._conn.fileno()

aiopg/cursor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def __iter__(self):
384384
while True:
385385
row = yield from self.fetchone()
386386
if row is None:
387-
raise StopIteration
387+
return
388388
else:
389389
yield row
390390

@@ -402,7 +402,7 @@ def __anext__(self):
402402
if ret is not None:
403403
return ret
404404
else:
405-
raise StopAsyncIteration # noqa
405+
raise StopAsyncIteration
406406

407407
@asyncio.coroutine
408408
def __aenter__(self):

aiopg/sa/result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def __iter__(self):
335335
while True:
336336
row = yield from self.fetchone()
337337
if row is None:
338-
raise StopIteration
338+
return
339339
else:
340340
yield row
341341

@@ -353,7 +353,7 @@ def __anext__(self):
353353
if ret is not None:
354354
return ret
355355
else:
356-
raise StopAsyncIteration # noqa
356+
raise StopAsyncIteration
357357

358358
def _non_result(self):
359359
if self._metadata is None:

aiopg/utils.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
try:
1616
ensure_future = asyncio.ensure_future
1717
except AttributeError:
18-
ensure_future = asyncio.async
18+
ensure_future = getattr(asyncio, 'async')
1919

2020

2121
def create_future(loop):
@@ -86,7 +86,20 @@ class _SAConnectionContextManager(_ContextManager):
8686
if PY_35: # pragma: no branch
8787
if PY_352:
8888
def __aiter__(self):
89-
return self._coro
89+
return self
90+
91+
@asyncio.coroutine
92+
def __anext__(self):
93+
if self._obj is None:
94+
self._obj = yield from self._coro
95+
96+
try:
97+
return (yield from self._obj.__anext__())
98+
except StopAsyncIteration:
99+
self._obj.close()
100+
self._obj = None
101+
raise
102+
90103
else:
91104
@asyncio.coroutine
92105
def __aiter__(self):

tests/test_pool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ def test_true_parallel_tasks(create_pool, loop):
343343
maxsize = 0
344344
minfreesize = 100
345345

346+
@asyncio.coroutine
346347
def inner():
347348
nonlocal maxsize, minfreesize
348349
maxsize = max(maxsize, pool.size)

0 commit comments

Comments
 (0)