Migrate Python API to websockets new asyncio API (>=14.0)#607
Open
mkusaka wants to merge 1 commit into
Open
Conversation
Remove the legacy/new API compatibility shim and migrate directly to the websockets 14.0+ API: - InvalidStatusCode → InvalidStatus (with response.status_code) - extra_headers → additional_headers - response_headers → response.headers - websockets.legacy.client.connect → websockets.connect - websockets.legacy.client.unix_connect → websockets.unix_connect - Pin websockets>=14.0 in setup.py Add tests for connection module covering protocol version parsing, InvalidStatus error handling (406/500/401), async_create error paths, and argument passing to connect methods.
Owner
|
Unfortunately it looks like we still have to support older versions of Python, while websockets 14 needs Python 3.9. For compatibility reasons, scripts are generally locked at the major version they were originally implemented in. That could be as old as Python 3.7. I don't have a good plan to get people off of ancient Pythons. Do you think we could maintain a backward compatibility codepath? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #604. Migrates
connection.pyfrom the legacy websockets API to the new asyncio-based API introduced in websockets 14.0, as discussed with @gnachman.Why websockets>=14.0?
websockets 14.0 is the first version where the new asyncio implementation became the default (changelog). In 13.0, the new implementation was introduced but opt-in; in 14.0,
websockets.connectandwebsockets.unix_connectpoint to the new API by default, and the legacy implementation was deprecated.Migration references
connect()docs (additional_headers,response.headers): https://websockets.readthedocs.io/en/stable/reference/asyncio/client.htmlInvalidStatusvsInvalidStatusCode(legacy): https://websockets.readthedocs.io/en/stable/reference/exceptions.htmlChanges
connection.pytry: import websockets.legacy.client/except)InvalidStatusCode→InvalidStatus(access viae.response.status_codeinstead ofe.status_code) —InvalidStatusCodeis legacy-onlyextra_headers=→additional_headers=— new API parameter nameresponse_headers→response.headers— new API usesClientConnection.responseobjectwebsockets.legacy.client.connect→websockets.connectwebsockets.legacy.client.unix_connect→websockets.unix_connect# type: ignorecomments (no longer needed)setup.pywebsockets>=14.0(first version where new asyncio API is the default)tests/test_connection.py(new, 12 tests)TestIterm2ProtocolVersion— version header parsing (4 tests)TestInvalidStatusHandling— 406/500/401 error handling inasync_connect(4 tests)TestAsyncCreate— 406/500 error handling inasync_create(2 tests)TestConnectCoroutineArgs—additional_headersparameter passing for TCP and Unix (2 tests)Test plan
pytest tests/test_connection.py— 12 passedpytest tests/— 154 passed (no regressions)(1, 11), 4 windows / 16 sessions listed