Skip to content

MypyServer

Base classes

Name Children Inherits
LSPServerInfo
anyenv.lsp_servers._base
Static configuration for an LSP server.

⋔ Inheritance diagram

graph TD
  365299137["python_lsps.MypyServer"]
  514706066["_base.LSPServerInfo"]
  2751680898["builtins.object"]
  514706066 --> 365299137
  2751680898 --> 514706066

🛈 DocStrings

Bases: LSPServerInfo

Mypy with JSON diagnostic parsing.

Source code in src/anyenv/lsp_servers/_servers/python_lsps.py
@dataclass
class MypyServer(LSPServerInfo):
    """Mypy with JSON diagnostic parsing."""

    def _parse_json_diagnostics(self, output: str) -> list[Diagnostic]:
        """Parse mypy JSON output (one JSON object per line)."""
        import anyenv

        diagnostics: list[Diagnostic] = []
        for line in output.strip().splitlines():
            line = line.strip()
            if not line or not line.startswith("{"):
                continue
            try:
                data = anyenv.load_json(line, return_type=dict)
                diagnostics.append(
                    Diagnostic(
                        file=data.get("file", ""),
                        line=data.get("line", 1),
                        column=data.get("column", 1),
                        severity=severity_from_string(data.get("severity", "error")),
                        message=data.get("message", ""),
                        code=data.get("code"),
                        source=self.id,
                    )
                )
            except anyenv.JsonLoadError:
                continue

        return diagnostics

:fa-brands-github: Show source on GitHub