-
Notifications
You must be signed in to change notification settings - Fork 185
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
Improve type stubs #2369
Improve type stubs #2369
Conversation
@@ -246,7 +249,7 @@ def list_items(self) -> List[sublime.ListInputItem]: | |||
text = "{}: {}".format(format_severity(diagnostic_severity(diagnostic)), first_line) | |||
annotation = format_diagnostic_source_and_code(diagnostic) | |||
kind = DIAGNOSTIC_KINDS[diagnostic_severity(diagnostic)] | |||
list_items.append(sublime.ListInputItem(text, (i, diagnostic), annotation=annotation, kind=kind)) | |||
list_items.append(sublime.ListInputItem(text, [i, diagnostic], annotation=annotation, kind=kind)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't mind a typed dict like
DiagnosticInputItem = TypedDict('DiagnosticInputItem', {
'index': int,
'diagnostic': Diagnostic
}, total=True)
(been testing it so wrote it already)
but... this still throws type error due to it being incompatible with Dict[str, Any]
. So if we'd need more hacks on top of that then it defeats the point.
Trying to compete with https://github.com/jfcherng-sublime/ST-API-stubs with those? ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't verify every modification in stubs manually but it looks pretty good.
Yeah, but those stubs only target the 3.8 API environment, and they use a few custom type definitions/aliases which would show up in the hover popup. At first I actually considered to start with jfcherng's stubs, but then it turned out to be easier to just take the original When LSP switches to the 3.8 API it should be relatively simple to go through the files again, in order to add the new enums, change the parameter names that are different, and to add the functions that are exclusive to the 3.8 API. Btw, I had hoped that you would squash the commits in this PR, because they are not really important and a bit of a mess, but nevermind :-) |
I have force-pushed now. Watch out for conflicts. |
In the type stubs for
sublime.py
andsublime_plugin.py
:int | str
instead ofUnion[int, str]
This also revealed a few inaccuracies in the code (return value of
View.sheet()
, use of deprecated constant, etc.), which I have fixed too.There is also a wrong type annotation in the current code base at
LSP/plugin/goto_diagnostic.py
Line 258 in fe32c17
because the
value
can never be atuple
, even if it was provided as a tuple for theListInputItem
constructor atLSP/plugin/goto_diagnostic.py
Line 249 in fe32c17
A tuple is incompatible with sublime.Value, it still works here, but internally it is converted to a list. You can confirm this with a little plugin like this:
Result:
I fixed this type incompatibility in the last commit (it looks a little bit ugly though, but I didn't want to extra add a new TypedDict for this).