Skip to content

Commit 997a626

Browse files
committed
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.
1 parent 42f634e commit 997a626

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/esbonio/esbonio/sphinx_agent/server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
import threading
1010
import traceback
11+
import typing
1112
from concurrent.futures import ThreadPoolExecutor
1213
from typing import Any
1314
from typing import TypeVar
@@ -33,10 +34,10 @@ def parse_message(obj: dict, cls: type[T]) -> T:
3334

3435
if dataclasses.is_dataclass(cls):
3536
kwargs = {}
36-
fields = {f.name: f for f in dataclasses.fields(cls)}
37+
fields = typing.get_type_hints(cls)
3738

3839
for key, value in obj.items():
39-
kwargs[key] = parse_message(value, fields[key].type)
40+
kwargs[key] = parse_message(value, fields[key])
4041

4142
return cls(**kwargs) # type: ignore[return-value]
4243

0 commit comments

Comments
 (0)