Fix mypy issues

This commit is contained in:
Dominik Jain authored and Dominik Jain committed 2025-11-19 22:32:29 +01:00
1 parent 11cb8f2811
commit b72fe2d45d
5 files changed
+17 -17

No files matched your search

+10 -10
View File
@@ -91,7 +91,7 @@ class DocumentSymbols:
self.root_symbols = root_symbols
self._all_symbols: list[ls_types.UnifiedSymbolInformation] | None = None
def __getstate__(self):
def __getstate__(self) -> dict:
return getstate(DocumentSymbols, self, transient_properties=["_all_symbols"])
def iter_symbols(self) -> Iterator[ls_types.UnifiedSymbolInformation]:
@@ -103,7 +103,7 @@ class DocumentSymbols:
yield from self._all_symbols
return
def traverse(s: ls_types.UnifiedSymbolInformation):
def traverse(s: ls_types.UnifiedSymbolInformation) -> Iterator[ls_types.UnifiedSymbolInformation]:
yield s
for child in s.get("children", []):
yield from traverse(child)
@@ -297,7 +297,7 @@ class SolidLanguageServer(ABC):
self.completions_available = threading.Event()
if config.trace_lsp_communication:
def logging_fn(source: str, target: str, msg: StringDict | str):
def logging_fn(source: str, target: str, msg: StringDict | str) -> None:
self.logger.log(f"LSP: {source} -> {target}: {msg!s}", self.logger.logger.level)
else:
@@ -673,10 +673,10 @@ class SolidLanguageServer(ABC):
new_item.update(item)
new_item["absolutePath"] = PathUtils.uri_to_path(new_item["uri"])
new_item["relativePath"] = PathUtils.get_relative_path(new_item["absolutePath"], self.repository_root_path)
ret.append(ls_types.Location(new_item))
ret.append(ls_types.Location(**new_item)) # type: ignore
elif LSPConstants.TARGET_URI in item and LSPConstants.TARGET_RANGE in item and LSPConstants.TARGET_SELECTION_RANGE in item:
new_item: ls_types.Location = {}
new_item["uri"] = item[LSPConstants.TARGET_URI]
new_item: dict = {} # type: ignore
new_item["uri"] = item[LSPConstants.TARGET_URI] # type: ignore
new_item["absolutePath"] = PathUtils.uri_to_path(new_item["uri"])
new_item["relativePath"] = PathUtils.get_relative_path(new_item["absolutePath"], self.repository_root_path)
new_item["range"] = item[LSPConstants.TARGET_SELECTION_RANGE] # type: ignore
@@ -688,7 +688,7 @@ class SolidLanguageServer(ABC):
assert LSPConstants.URI in response
assert LSPConstants.RANGE in response
new_item = {}
new_item: dict = {} # type: ignore
new_item.update(response)
new_item["absolutePath"] = PathUtils.uri_to_path(new_item["uri"])
new_item["relativePath"] = PathUtils.get_relative_path(new_item["absolutePath"], self.repository_root_path)
@@ -802,18 +802,18 @@ class SolidLanguageServer(ABC):
with self.open_file(relative_file_path):
response = self.server.send.text_document_diagnostic(
{
LSPConstants.TEXT_DOCUMENT: {
LSPConstants.TEXT_DOCUMENT: { # type: ignore
LSPConstants.URI: pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri()
}
}
)
if response is None:
return []
return [] # type: ignore
assert isinstance(response, dict), f"Unexpected response from Language Server (expected list, got {type(response)}): {response}"
ret: list[ls_types.Diagnostic] = []
for item in response["items"]:
for item in response["items"]: # type: ignore
new_item: ls_types.Diagnostic = {
"uri": pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri(),
"severity": item["severity"],
+4 -4
View File
@@ -315,7 +315,7 @@ class SolidLanguageServerHandler:
if self.logger is not None:
self.logger("client", "logger", message)
def _read_bytes_from_process(self, process, stream, num_bytes):
def _read_bytes_from_process(self, process, stream, num_bytes) -> bytes: # type: ignore
"""Read exactly num_bytes from process stdout"""
data = b""
while len(data) < num_bytes:
@@ -385,9 +385,9 @@ class SolidLanguageServerHandler:
line = self.process.stderr.readline()
if not line:
continue
line = line.decode(ENCODING, errors="replace")
level = self._determine_log_level(line)
log.log(level, line)
line_str = line.decode(ENCODING, errors="replace")
level = self._determine_log_level(line_str)
log.log(level, line_str)
except Exception as e:
log.error("Error while reading stderr from language server process: %s", e, exc_info=e)
if not self._is_shutting_down:
+1 -1
View File
@@ -409,4 +409,4 @@ def extract_text_edits(workspace_edit: WorkspaceEdit) -> dict[str, list[TextEdit
changes[uri] = edits
return changes
else:
raise f"Invalid WorkspaceEdit (expected 'changes' or 'documentChanges' key):\n{workspace_edit}"
raise Exception(f"Invalid WorkspaceEdit (expected 'changes' or 'documentChanges' key):\n{workspace_edit}")
+1 -1
View File
@@ -2,7 +2,7 @@ import platform
import subprocess
def subprocess_kwargs():
def subprocess_kwargs() -> dict:
"""
Returns a dictionary of keyword arguments for subprocess calls, adding platform-specific
flags that we want to use consistently.
+1 -1
View File
@@ -115,7 +115,7 @@ class SafeZipExtractor:
"""
if sys.platform.startswith("win"):
return Path(rf"\\?\{os.path.abspath(path)}")
return path
return path # type: ignore
# Example usage: