Description
When deserialising a payload and specifying one of the fields of type msgspec.Raw, it prohibits passing payload as str.
Code to reproduce:
import msgspec
class Foo(msgspec.Struct):
d: msgspec.Raw
data = '{"d": {"test": "A"}}'
decoder = msgspec.json.Decoder(Foo)
decoder.decode(data)
Output:
# python3 --version
Python 3.10.6
# python3 -m pip freeze | grep msgspec
msgspec==0.13.1
# python3 foo.py
Traceback (most recent call last):
File "./foo.py", line 10, in <module>
decoder.decode(data)
TypeError: a bytes-like object is required, not 'str'
Changing the payload to a bytes works as expected. Also worth noting that removing Raw and changing it to a proper type works also as expected.
I would like to have a go at fixing this bug, but don't know where to start, as there is no code that points to Raw not allowing a string (which if you pass a value directly to it, it works as expected):
>>> import msgspec
>>> msgspec.Raw("test")
<msgspec.Raw object at 0x7c3889bb70>
so will have to look further into it. Any help in the right direction is appreciated :)
Description
When deserialising a payload and specifying one of the fields of type
msgspec.Raw, it prohibits passing payload asstr.Code to reproduce:
Output:
Changing the payload to a bytes works as expected. Also worth noting that removing
Rawand changing it to a proper type works also as expected.I would like to have a go at fixing this bug, but don't know where to start, as there is no code that points to
Rawnot allowing a string (which if you pass a value directly to it, it works as expected):so will have to look further into it. Any help in the right direction is appreciated :)