Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace "transports" with "writers" #508

Merged
merged 3 commits into from
Oct 30, 2024
Merged

Conversation

alcarney
Copy link
Collaborator

@alcarney alcarney commented Oct 27, 2024

This PR requires #507 be merged first

Now that we use the high-level asyncio APIs, it no longer makes sense for JsonRPCProtocol to be a subclass of asyncio.Protocol. This PR converts JsonRPCProtocol into a simple class, cleaning up some dead code in the process

It also

  • renames the concept of "transport" to "writer" which aligns better with the reader/writer pair you often see in the high-level asyncio APIs.

  • renames the connection_made method to set_writer, also incorporating an include_headers flag.
    Before

    protocol._send_only_body = True  # Don't send headers within the payload
    protocol.connection_made(WebSocketTransportAdapter(websocket))

    After

    protocol.set_writer(WebSocketWriter(websocket), include_headers=False)  
  • Adds relevant typing protocols and writer classes to the pygls.io_ module

  • Tweaks the handling of writers, so that both sync and async methods on the writer object can be used.

Code review checklist (for code reviewer to complete)

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • Title summarizes what is changing
  • Commit messages are meaningful (see this for details)
  • Tests have been included and/or updated, as appropriate
  • Docstrings have been included and/or updated, as appropriate
  • Standalone docs have been updated accordingly

Automated linters

You can run the lints that are run on CI locally with:

poetry install --all-extras --with dev
poetry run poe lint

@alcarney alcarney mentioned this pull request Oct 27, 2024
9 tasks
Now that we use the high-level asyncio APIs, it no longer makes sense
for `JsonRPCProtocol` to be a subclass of `asyncio.Protocol`. This
commit converts `JsonRPCProtocol` into a simple class, cleaning up
some dead code in the process
Another artifact of being based on `asyncio.Protocol` was that pygls'
output object was called a "transport"

This commit

- renames the concept to "writer" which aligns better with the
  reader/writer pair you often see in the high-level asyncio APIs.
- renames the `connection_made` method to `set_writer`, also
  incorporating an `include_headers` flag.
- Adds relevant typing protocols and writer classes to the `pygls.io_`
  module
@alcarney alcarney marked this pull request as ready for review October 28, 2024 18:41
@alcarney alcarney requested a review from tombh October 28, 2024 18:41
Copy link
Collaborator

@tombh tombh left a comment

Choose a reason for hiding this comment

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

So clean and new 🥹 You're really cleaning up the core.

@alcarney
Copy link
Collaborator Author

Thanks!

@alcarney alcarney merged commit 1572399 into openlawlibrary:main Oct 30, 2024
16 checks passed
@alcarney alcarney deleted the writers branch October 30, 2024 19:51
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