Psycopg2: Python 3.7 support: async is a keyword

Created on 18 May 2018  ·  19Comments  ·  Source: psycopg/psycopg2

According to PEP 492, async and await are now keywords and cannot be used as names.

psycopg2 does:

  File "/usr/lib64/python3.7/site-packages/psycopg2/tests/test_async_keyword.py", line 43
    self.conn = self.connect(async=True)
                                 ^
SyntaxError: invalid syntax
  File "/usr/lib64/python3.7/site-packages/psycopg2/tests/test_cursor.py", line 570
    connect_func = lambda: self.connect(async=True)
                                            ^
SyntaxError: invalid syntax

Can this be renamed, to asynch maybe or async_?

Most helpful comment

It is already fixed: since psycopg 2.7 you can use async_ instead. The tests should probably be fixed (at the moment Python 3.7 is not in travis) but the lib itself should work.

All 19 comments

It is already fixed: since psycopg 2.7 you can use async_ instead. The tests should probably be fixed (at the moment Python 3.7 is not in travis) but the lib itself should work.

Running on Travis CI to see what happens BTW: https://travis-ci.org/hroncok/psycopg2/jobs/380610023

Would you accept a PR that fixes the tests and enables 3.7 on Travis?

Funny enough the tests pass as they are.

test_async_keyword.py, as the name says, is conditionally excluded from the test suite, see tests/__init__.py. test_cursor.py seems broken and can be changed using async_.

Of course I'm happy to accept running the tests on 3.7 too, thank you :)

Weird the tests pass as they are. I would have expected test_cursor to fail importing.

As of 2.7 the tests were passing on python 3.7. The cursor test was broken in psycopg 2.7.2 by b203a7c775c5f81f59c6b4205c3c33455ceeec3d

ef64493

this is in master but not in maint_2_7. Will cherry-pick.

Thanks a lot. I've added 3.7 to Travis in https://github.com/psycopg/psycopg2/pull/715

This issue can be considered invalid:

test_cursor fixed too. However 3.7 tests cannot run automatically on the branch maint_2_7 because it still supports Python 3.2, which instead is no more supported by recent pip versions (see this failure).

That's no big deal: I'd start push psycopg 2.8 instead.

@dvarrazzo Debian migrated to python 3.7 in unstable. Do you have an ETA for 2.8? :)

Cheers!

No, no release date yet, working on a couple of experimental branches.

However psycopg 2.7.5 runs perfectly well on python 3.7: try

$ make PYTHON=/usr/local/py37/bin/python3
$ make PYTHON=/usr/local/py37/bin/python3 check

At the moment, installing python3-psycopg2 2.7.5-1+b1 on Debian unstable explodes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=902715

Thanks @hroncok for the pointer; I've done mostly the same thing when uploading an updated psycopg2 that fixes the install issue in Debian.

FWIW, @dvarrazzo, the concrete issue here is that when installing Python modules, Debian will byte-compile all files for all supported versions, even if they're never imported. The test_async_keyword.py file can't be byte-compiled by 3.7 (because it uses async as a variable), so the install blows up. The "fix" is to stop shipping the file in the binary packages.

Thanks for maintaining psycopg2, and sorry for the noise :)

Thanks a lot. We have similar case where in our exist pipeline where we will manually compile all files with python3 -m compileall . and deploy the *.pyc only. Our current workaround is to remove the test_async_keyword.py before compiling

Was this page helpful?
0 / 5 - 0 ratings