question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

asyncio/websocket.py not compatible with Python 3.7 syntax changes

See original GitHub issue

This change in Python 3.7:

Backwards incompatible syntax changes:

async and await are now reserved keywords.

Broke this code block in asyncio/websocket.py:

if hasattr(asyncio, 'ensure_future'):
    ensure_future = asyncio.ensure_future
else:  # Deprecated since Python 3.4.4
    ensure_future = asyncio.async

Example failure log:

Traceback (most recent call last):
 File REDACTED, line 18, in <module>
   from autobahn.asyncio.websocket import WebSocketServerFactory, WebSocketServerProtocol
 File “/usr/local/lib/python3.7/site-packages/autobahn/asyncio/__init__.py”, line 36, in <module>
   from autobahn.asyncio.websocket import \
 File “/usr/local/lib/python3.7/site-packages/autobahn/asyncio/websocket.py”, line 52
   ensure_future = asyncio.async
                               ^
SyntaxError: invalid syntax

I fixed the issue locally by just deleting the old import, but I don’t know what preferred fix in autobahn official library is. It would probably work to use getattr(asyncio, “async”) to preserve backwards compatibility while still respecting the new Python 3.7 syntax rules.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
nicolas-leydetcommented, Jul 9, 2018

from @meejah We will want to support Python 3.4 for now

The fix proposed by @Ardonius should do exactly that:

if hasattr(asyncio, 'ensure_future'):
    ensure_future = asyncio.ensure_future
else:  # Deprecated since Python 3.4.4
    ensure_future = getattr(asyncio, "async")
0reactions
agronholmcommented, Jul 13, 2018

Even if I use the latest version, the test suite still fails because it tries to import a nonexistent module (asyncio.test_utils).

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's New In Python 3.7 — Python 3.11.1 documentation
This article explains the new features in Python 3.7, compared to 3.6. Python 3.7 was released on June 27, 2018. ... Backwards incompatible...
Read more >
What's New In Python 3.8 — Python 3.11.1 documentation
This article explains the new features in Python 3.8, compared to 3.7. ... are handled by the script); this change is backward incompatible...
Read more >
What's New In Python 3.9 — Python 3.11.1 documentation
These paths now remain valid after the current directory is changed by ... asyncio now raises TyperError when calling incompatible methods with an...
Read more >
What's New In Python 3.10 — Python 3.11.1 documentation
This article explains the new features in Python 3.10, compared to 3.9. Python 3.10 was released on October 4, 2021. For full details,...
Read more >
PEP 606 – Python Compatibility Version
Any incompatible change can break an unknown number of Python projects. ... In Python 3.7, a __getattr__() has been added to the collections ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found