11import uuid
22from collections .abc import Iterable
33from importlib .metadata import version
4- from typing import cast , get_args
4+ from typing import Final , cast , get_args
55
66import attr
77import cattrs
@@ -42,7 +42,7 @@ def make_import_text_edit(import_text: str) -> lsp.TextEdit:
4242
4343
4444def make_text_edit (edit : Edit ) -> lsp .TextEdit :
45- node_range = edit .node .range ()
45+ node_range : Final = edit .node .range ()
4646 return lsp .TextEdit (
4747 range = lsp .Range (
4848 start = lsp .Position (line = node_range .start .line , character = node_range .start .column ),
@@ -55,7 +55,7 @@ def make_text_edit(edit: Edit) -> lsp.TextEdit:
5555def make_diagnostics (source : str ) -> Iterable [lsp .Diagnostic ]:
5656 if not IMPORT_CONFIG :
5757 return
58- result = make_replacements (root = SgRoot (source , "python" ).root (), import_config = IMPORT_CONFIG )
58+ result : Final = make_replacements (root = SgRoot (source , "python" ).root (), import_config = IMPORT_CONFIG )
5959
6060 for replacement in result .replacements :
6161 if replacement .operation_type == AddFinal :
@@ -86,7 +86,7 @@ def make_diagnostics(source: str) -> Iterable[lsp.Diagnostic]:
8686def make_fixall_text_edits (source : str ) -> Iterable [lsp .TextEdit ]:
8787 if not IMPORT_CONFIG :
8888 return
89- result = make_replacements (root = SgRoot (source , "python" ).root (), import_config = IMPORT_CONFIG )
89+ result : Final = make_replacements (root = SgRoot (source , "python" ).root (), import_config = IMPORT_CONFIG )
9090
9191 for replacement in result .replacements :
9292 for edit in replacement .edits :
@@ -147,7 +147,7 @@ def workspace_did_change_configuration(params: lsp.DidChangeConfigurationParams)
147147def did_open_did_save_did_change (
148148 params : lsp .DidOpenTextDocumentParams | lsp .DidSaveTextDocumentParams | lsp .DidChangeTextDocumentParams ,
149149) -> None :
150- text_document = LSP_SERVER .workspace .get_text_document (params .text_document .uri )
150+ text_document : Final = LSP_SERVER .workspace .get_text_document (params .text_document .uri )
151151 LSP_SERVER .publish_diagnostics (text_document .uri , diagnostics = list (make_diagnostics (text_document .source )))
152152
153153
@@ -163,12 +163,12 @@ def did_close(params: lsp.DidCloseTextDocumentParams) -> None:
163163 ),
164164)
165165def code_action (params : lsp .CodeActionParams ) -> list [lsp .CodeAction ] | None :
166- requested_kinds = params .context .only or {lsp .CodeActionKind .QuickFix , lsp .CodeActionKind .SourceFixAll }
167- actions : list [lsp .CodeAction ] = []
166+ requested_kinds : Final = params .context .only or {lsp .CodeActionKind .QuickFix , lsp .CodeActionKind .SourceFixAll }
167+ actions : Final [ list [lsp .CodeAction ] ] = []
168168
169169 if lsp .CodeActionKind .QuickFix in requested_kinds :
170- text_document = LSP_SERVER .workspace .get_text_document (params .text_document .uri )
171- our_diagnostics = [
170+ text_document : Final = LSP_SERVER .workspace .get_text_document (params .text_document .uri )
171+ our_diagnostics : Final = [
172172 diagnostic for diagnostic in params .context .diagnostics if diagnostic .source == LSP_SERVER .name
173173 ]
174174
@@ -210,7 +210,7 @@ def code_action(params: lsp.CodeActionParams) -> list[lsp.CodeAction] | None:
210210
211211@LSP_SERVER .feature (lsp .CODE_ACTION_RESOLVE )
212212def resolve_code_action (params : lsp .CodeAction ) -> lsp .CodeAction :
213- text_document = LSP_SERVER .workspace .get_text_document (cast (str , params .data ))
213+ text_document : Final = LSP_SERVER .workspace .get_text_document (cast (str , params .data ))
214214 params .edit = lsp .WorkspaceEdit (
215215 document_changes = [
216216 lsp .TextDocumentEdit (
0 commit comments