Currently, string literals can't be used as dict keys in a Struct. See example below:
from typing import Literal
from msgspec import Struct, json
AorB = Literal["a", "b"]
class Test(Struct):
d: dict[AorB, float]
data = Test(d={'a': 1.0, 'b': 2.0})
encoded = json.encode(data)
print(encoded)
decoded = json.decode(encoded, type=Test) # TypeError: JSON doesn't support dicts with non-string keys - type `dict[typing.Literal['a', 'b'], float]` is not supported
I would think it should be allowed - but I'd like to hear your thoughts.
Currently, string literals can't be used as dict keys in a
Struct. See example below:I would think it should be allowed - but I'd like to hear your thoughts.