Skip to content

Commit

Permalink
sphinx-agent: Fix message parsing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alcarney committed Jul 21, 2024
1 parent 42f634e commit 997a626
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/esbonio/esbonio/sphinx_agent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]

Expand Down

0 comments on commit 997a626

Please sign in to comment.