Dear #lazyweb, what is the best way you know to represent #tagged #enums in #Python? It needs to be at least somewhat type-checkable, although it's possible I might settle for something like enumerating each value's associated data type/tuple once again for mypy to see.

So far I've been using a hierarchy of frozen dataclasses and then a single-dispatch handler; however, now I have a possible use case with the need for validation, and the hierarchy of dataclasses is not discoverable, thus not, well, enumerable :)

To give an example of what I mean by a tagged enum:

class Meow(WhatGoesHereIWonder):
Mrrp(int) = "mrrp"
Mya = "no-args-just-mya"
Mrrrrreowww(ComplexType, str) = "mreow"

@mrrmot you might be ok with an union?

While i did a lot of python, i must say i didn't experiment much with this kind of checking, though Rust familiarized me with the concept, so you might run into issues i don't anticipate.

@tshirtman Sorry for not replying sooner, but this is actually a great suggestion - a union of objects that can hold their own data (scalars, (named) tuples, dataclasses, etc) is pretty much exactly what I was looking for in this particular case. Thanks!
@mrrmot Glad to hear that! 😄