Type annotation improvments#543
Merged
Merged
Conversation
25d2078 to
22db68b
Compare
This commit updates some of the type annotations in the `JsonRPCProtocol` class to be more accurate, reduce the number of false errors when running pyright lsp and hopefully, improve the quality of completion suggestions. The easiest way to "fix" the `handle_message` appeared to be to create a bunch of `Protocols` that describe the shape of incoming messages and use `isinstance` to pick between them. This does mean duplicating all of our fallback message types but I don't think that can be avoided as you cannot create an instance of a protocol. There are still more cases to fix, but this should be a step in the right direction.
22db68b to
16480b8
Compare
Collaborator
Author
|
I'll look into fixing pyodide in a separate PR |
Collaborator
Author
|
Thanks! |
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.
Description (e.g. "Related to ...", etc.)
This PR tries to improve the type annotations in various parts of the codebase, they're far from perfect but this is hopefully a step in the right direction. Highlights include
Server methods that return a future now specify the type of the result
Client methods that return a future now specify the type of the result
The
get_capabilityfunction now has a long list of@typing.overloaddeclarations so that your editor can help you with both the name of the capabilityand the shape of the result
Both
types.ServerCapabilitiesandtypes.ClientCapabilitiesare supportedI've also included 1475823 so that pygls better handles responses with unknown ids (see #541)
Code review checklist (for code reviewer to complete)
Automated linters
You can run the lints that are run on CI locally with: