If I have some simple sum type in Haskell, like
data Owner = Me | You
How do I express that in Python in a convenient way?
An Enum or a Union is the closest thing to a tagged union or sum type in Python.
from enum import Enum
class Owner(Enum):
    Me = 1
    You = 2
https://docs.python.org/3/library/typing.html#typing.Union
import typing
class Me:
    pass
class You:
    pass
owner: typing.Union[Me, You] = Me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With