Skip to content

msgspec.inspect error #807

Open
Open
@lblanquet

Description

@lblanquet

Description

I want to define JSON fields.
I thus use the following code.

import msgspec
import uuid
from typing import TypeAlias

t_JSON: TypeAlias = dict[str, "t_JSON"] | list["t_JSON"] | str | int | float | bool | None

class t_1(msgspec.Struct):
        n: int
        uid: uuid.UUID
        jdata: t_JSON

print('Version:', msgspec.__version__)
msgspec.inspect.type_info(t_1)

and it issues an exception (I don't know if it's actually a bug):

Version: 0.19.0
Traceback (most recent call last):
  File "c:\program files\wing pro 10\bin\dbg\src\debug\tserver\dbgutils.py", line 2334, in to_trace
  Python Shell, prompt 6, line 1
    msgspec.inspect.type_info(t_1)
  File "d:\python\python312\lib\site-packages\msgspec\inspect.py", line 629, in type_info
    return multi_type_info([type])[0]
  File "d:\python\python312\lib\site-packages\msgspec\inspect.py", line 598, in multi_type_info
    return _Translator(types).run()
  File "d:\python\python312\lib\site-packages\msgspec\inspect.py", line 744, in run
    MsgpackDecoder(Tuple[self.types])
builtins.TypeError: Type 'ForwardRef('t_JSON')' is not supported```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions