yukinarit/pyserde

Deserializing enum variant with no fields into a dataclass with no fields fails

Closed this issue · 4 comments

If you serialize enum variant with no fields using serde, it will produce a string with just the name of that variant. I would have expected to be able to deserialize that into a dataclass with no fields, i.e. into this:

@serde
@dataclass
class EnumVariantWithNoFields:
    pass

but this currently fails with a confusing error: "Failed to deserialize into EnumVariantWithNoFields: string indices must be integers, not 'str'".

It already works with fields - I can deserialize enum variant with fields into data class with fields.. this is just an edge case where variant has no fields.

I would also suggest adding some tests to check successful roundtrips against default serde (de)serialization, as that's probably what many users of this lib are after.

Hi @nirvana-msu
There is no test case for union with dataclass with no fields. Indeed, pyserde should support such a case.

Hi @nirvana-msu
Can you please post a test case here? I have time to work on this.

Sorry I don't know how to reproduce it. Please reopen the issue if you are ready to provide a minimum reproducible code.