You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, and thanks as always for the amazing library.
I have a use case where I'm decoding a document with a huge amount of types, only a handful of which I care about. The schema uses tagged unions, and I'm hoping there is a way to to essentially ignore and/or simply leave as dict and objects that have an unrecognized type. As a simple example, I'd like to be able to deal with the "type": "Other" object below:
Traceback (most recent call last):
File "/Users/talley/dev/self/slydb/y.py", line 23, in <module>print(dec.decode(msg))
^^^^^^^^^^^^^^^msgspec.ValidationError: Invalid value 'Other' - at `$[2].type`
alternatives I have considered
I tried using something like msgspec.json.Decoder(list[Get | Put | dict]), but that results in:
TypeError: Type unions may not contain more than one dict-like type (`Struct`, `dict`, `TypedDict`, `dataclass`) - type `__main__.Get | __main__.Put | dict` is not supported
the only other thing I can think of is to (laboriously) define stub Structs for every key I ever encounter but don't care about. i.e. add:
Yes it works, but it means that you need to know ahead of time the literal string of every type name you're ever going to encounter, even if you don't care about them (and would be happy to either leave them as unstructured dicts or empty structs)
(Assume that there are many additional names, not just Other)
Question
Hello, and thanks as always for the amazing library.
I have a use case where I'm decoding a document with a huge amount of types, only a handful of which I care about. The schema uses tagged unions, and I'm hoping there is a way to to essentially ignore and/or simply leave as
dict
and objects that have an unrecognized type. As a simple example, I'd like to be able to deal with the"type": "Other"
object below:alternatives I have considered
I tried using something like
msgspec.json.Decoder(list[Get | Put | dict])
, but that results in:the only other thing I can think of is to (laboriously) define stub
Structs
for every key I ever encounter but don't care about. i.e. add:and then hope i don't encounter something later that I haven't seen before...
tips?
The text was updated successfully, but these errors were encountered: