From 997a62624bae550dbb4f245b8d2a37c1705fcc99 Mon Sep 17 00:00:00 2001 From: Alex Carney Date: Sun, 21 Jul 2024 19:37:44 +0100 Subject: [PATCH] sphinx-agent: Fix message parsing Using `from __future__ import annotations` in more places meant that the field's types were coming through as strings. Using `typing.get_type_hints` ensures that these references are resolved correctly. --- lib/esbonio/esbonio/sphinx_agent/server.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/esbonio/esbonio/sphinx_agent/server.py b/lib/esbonio/esbonio/sphinx_agent/server.py index 066e90a2..18cfaeb0 100644 --- a/lib/esbonio/esbonio/sphinx_agent/server.py +++ b/lib/esbonio/esbonio/sphinx_agent/server.py @@ -8,6 +8,7 @@ import sys import threading import traceback +import typing from concurrent.futures import ThreadPoolExecutor from typing import Any from typing import TypeVar @@ -33,10 +34,10 @@ def parse_message(obj: dict, cls: type[T]) -> T: if dataclasses.is_dataclass(cls): kwargs = {} - fields = {f.name: f for f in dataclasses.fields(cls)} + fields = typing.get_type_hints(cls) for key, value in obj.items(): - kwargs[key] = parse_message(value, fields[key].type) + kwargs[key] = parse_message(value, fields[key]) return cls(**kwargs) # type: ignore[return-value]