-
Notifications
You must be signed in to change notification settings - Fork 182
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
refactor(types): Mark properties with NotRequired #2062
Conversation
from typing import TypeVar | ||
from typing import Union | ||
from typing_extensions import NotRequired | ||
from typing_extensions import Required | ||
from typing_extensions import TypedDict |
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.
typing_extensions is a third-party package, so this won't work on python 3.8.
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.
In 3.8 we could keep using real imports for type checking and dummy ones for the plugin host, like we do now.
Then:
- this won't really matter
- if we set python version to 3.11 for pyright then we can import those from
typing
One thing I'm not sure about (although it doesn't matter for ST) is how both pyright and mypy don't have problems with this typing_extensions
import. I guess that they either come with own copies or use system ones?
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.
Addressing in #2067
* main: Fix issues with diagnostics panel toggling on save (#2063) Request color presentations when clicking on a color box (#2065) Import new imports like NotRequired from "typing" Ensure "Source Actions..." request includes the "source" kind (#2064) refactor(types): Mark properties with NotRequired (#2062) Add template variable `$text_document_position` in execute command (#2061) Only update content of diagnostics panel when visible (#2054) Remove Range class and rename RangeLsp to Range (#2058)
Make use of auto-generated types from https://github.com/sublimelsp/lsp-python-types that utilize
NotRequired
for properties that might not be present.https://github.com/sublimelsp/lsp-python-types generates two separate files -
lsp_types.py
andlsp_types_sublime_text_33.py
. Former uses new class syntax that is documentation-annotations-friendly but is not compatible with Python 3.3. Latter doesn't use the new class syntax. We have to use the latter which means that documentation for properties won't be picked up by pyright but otherwise there are no downsides.Even though ST's 3.3 host doesn't support
NotRequired
(or eventyping
for that matter), that doesn't matter because for 3.3 the existing LSP code has a dummy type aliases that do nothing anyway. The important part is that type checkers likemypy
andpyright
type-check using Python version that supports those types.Some notes about changes:
WorkspaceFolder
class conflicted with same-named LSP type. Moved our class toworkspace.py
. Since it's a public export, plugins that imported it fromLSP.plugin
will be unaffected. The few that imported fromLSP.core.protocol
will be updated and I took care of that.Cannot resolve name "X" (possible cyclic definition)
. This is seemingly already supported onmaster
(as an opt-in) but not released yet. For now mypy is disabled due to that. I'm not sure but I don't think we can ignore type errors for specific file as if mypy can't process those types then I don't think it would be able to type check anyway.Promise
.pyright
intox.ini
and CI and fixedalmostall errors that it reported.The remaining ones are the stupid cases likeview = None # type: sublime.View
that I think we shouldn't be doing as that looks and feels wrong. Haven't investigated how we could fix those yet. Potentially we can just ignore those.