Motor 1.2.2: incompatible with Python 3.7

256 views
Skip to first unread message

Roman Bulgakov

unread,
Jul 9, 2018, 7:02:52 PM7/9/18
to mongodb-user
Python 3.7 was released recently.

Motor library is incompatible with Python 3.7 because of syntax change:

Python 3.7 had declared words "async" and "await" as reserved keywords (release notes) and any attempt to use them as function/class/variable name are now producing `SyntaxError`

Because of that - motor cannot be used with AsyncIO on Python 3.7.

`asyncio` module had "async" function in the past, which was deprecated since version 3.4.4 (docs). and removed in Python 3.7

Motor uses an backward-compatibility fix to work on Python 3.4 here:

motor/frameworks/asyncio/__init__.py , line 32

try:
    from asyncio import ensure_future
except ImportError:
    from asyncio import async as ensure_future  # line 32

which now produces SyntaxError and prevents Motor from loading on Python 3.7. (without that line it works okay)


How can that be mitigated?  I suppose the only option is to drop support for Python 3.4.3 and lower...

Would you make a bugfix release? or we should wait for 1.3 / 2.0 ?

Roman Bulgakov

unread,
Jul 10, 2018, 4:16:05 PM7/10/18
to mongodb-user
found a better way to rewrite it, without dropping support for Python < 3.4.4, replace aforementioned code with this:

import asyncio

try:
    ensure_future = asyncio.ensure_future
except AttributeError:
    ensure_future = getattr(asyncio, "async")


вторник, 10 июля 2018 г., 2:02:52 UTC+3 пользователь Roman Bulgakov написал:

Bernie Hackett

unread,
Jul 11, 2018, 11:10:00 AM7/11/18
to mongodb-user
Motor 1.2.4, released today, fixes the aync keyword problem with Python 3.7:

Roman Bulgakov

unread,
Jul 11, 2018, 1:11:17 PM7/11/18
to mongodb-user
Motor 1.2.4 didn't fix the aforementioned issue.

code at motor/frameworks/asyncio/__init__.py:32 is still the same and still throws "SyntaxError: invalid syntax" (I've checked sources of package and on GitHub)

Traceback (most recent call last):
  File "/src/apps/applications.py", line 1, in <module>
    from appmanager.adapters import AppMongoStorageAdapter
  File "/src/appmanager/adapters.py", line 4, in <module>
    from microcore.storage.mongo import SimpleMongoStorageAdapter, motor
  File "/src/microcore/storage/mongo.py", line 6, in <module>
    from motor.motor_asyncio import AsyncIOMotorClient
  File "/venv/lib/python3.7/site-packages/motor/motor_asyncio.py", line 18, in <module>
    from .frameworks import asyncio as asyncio_framework
  File "/venv/lib/python3.7/site-packages/motor/frameworks/asyncio/__init__.py", line 32
    from asyncio import async as ensure_future
                            ^
SyntaxError: invalid syntax

Process finished with exit code 1

version:

> pip freeze | grep motor
motor==1.2.4

> python3 --version
Python 3.7.0





среда, 11 июля 2018 г., 18:10:00 UTC+3 пользователь Bernie Hackett написал:

Roman Bulgakov

unread,
Jul 11, 2018, 1:20:15 PM7/11/18
to mongodb-user
Motor 1.3 has same issue.

Motor 2.0 is fine.


среда, 11 июля 2018 г., 18:10:00 UTC+3 пользователь Bernie Hackett написал:
Motor 1.2.4, released today, fixes the aync keyword problem with Python 3.7:

A. Jesse Jiryu Davis

unread,
Jul 11, 2018, 2:34:28 PM7/11/18
to mongodb-user
Thanks for the report, I made a mistake and didn't backport the fix for the "async" keyword from the 2.0 release to the other releases. I've now uploaded Motor 1.3.1 and 1.2.5 with the fix.
Reply all
Reply to author
Forward
0 new messages