Skip to content

Remove client class - #27

Closed
mehaase wants to merge 4 commits into
async_resourcefrom
remove_client_class
Closed

mehaase wants to merge 4 commits into
async_resourcefrom
remove_client_class

Conversation

@mehaase

@mehaase mehaase commented Sep 17, 2018

Copy link
Copy Markdown
Contributor

As mentioned in #24, the WebSocketClient class is a confusing and unnecessary part of the API. This PR replaces that class with a context manager. It also adds support for opening a WebSocket by URL.

Instead of instantiating a client object and calling connect(),
you now call open_websocket(), which is an async context manager.
@mehaase
mehaase requested a review from belm0 September 17, 2018 17:43
@mehaase mehaase mentioned this pull request Sep 17, 2018
Comment thread README.md Resolved
Comment thread README.md Resolved


@asynccontextmanager
@async_generator

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the @async_generator belongs here, try removing it

@asynccontextmanager implies a generator that yields a single value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs async_generator is required for compatibility with Python 3.5 (which is the minimum version specified in setup.py right now). Even with Python 3.6, contrary to what the docs say, it broke when I removed it.

Comment thread trio_websocket/__init__.py Outdated

@asynccontextmanager
@async_generator
async def open_websocket_url(nursery, url, ssl_context=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can make this a non-async, non-contextmanager function which simply defers to open_websocket() (literally return open_websocket(...))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes, you're right!

@mehaase

mehaase commented Sep 18, 2018

Copy link
Copy Markdown
Contributor Author

Merged directly to master.

@mehaase mehaase closed this Sep 18, 2018
@mehaase
mehaase deleted the remove_client_class branch September 28, 2018 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants