Currently there's an issue where msgspec cannot convert a dataclass that contains forward references. This isn't unusual or msgspec specific, it is however a problem when trying to use msgspec to convert dataclasses that you don't have control over, i.e. cannot change the fact that they contain forward references.
# a.py
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Any
@dataclass
class Some:
value: Any
# b.py
from a import Some
import msgspec
# this fails with NameError: name 'Any' is not defined
msgspec.convert({"value": "something"}, type=Some)
A simple interface that would allow passing a custom set of globals to the internally used get_class_annotations would do the trick I think. Or is there another solution here that I'm not aware of? :)
Description
Currently there's an issue where msgspec cannot convert a dataclass that contains forward references. This isn't unusual or msgspec specific, it is however a problem when trying to use msgspec to convert dataclasses that you don't have control over, i.e. cannot change the fact that they contain forward references.
A simple interface that would allow passing a custom set of globals to the internally used
get_class_annotations
would do the trick I think. Or is there another solution here that I'm not aware of? :)