I've noticed that when encoding a dataclass class (as opposed to an instance), the class is encoded to an empty dict.
I was wondering if this was intentional behaviour? I would have expected an error as if I had passed in any other class (rather than instance).
>>> import msgspec.json
>>> e = msgspec.json.Encoder()
>>> from dataclasses import dataclass
>>> @dataclass
... class SomeDataclass:
... foo: int
...
>>> e.encode(SomeDataclass)
b'{}'
>>> class SomeClass:
... pass
...
>>> e.encode(SomeClass)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Encoding objects of type type is unsupported
Question
I've noticed that when encoding a dataclass class (as opposed to an instance), the class is encoded to an empty dict.
I was wondering if this was intentional behaviour? I would have expected an error as if I had passed in any other class (rather than instance).