Metadata-Version: 2.1
Name: tagged-dataclasses
Version: 0.0.2
Summary: 
Home-page: https://github.com/andreycizov/python-tagged_dataclasses
License: MIT
Keywords: tagged union
Author: Andrey Cizov
Author-email: acizov@gmail.com
Requires-Python: >=3.6,<4.0
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Requires-Dist: dataclasses (>0.1); python_version < "3.7"
Requires-Dist: typing_inspect (>=0.6,<0.7)
Project-URL: Documentation, https://github.com/andreycizov/python-tagged_dataclasses
Project-URL: Repository, https://github.com/andreycizov/python-tagged_dataclasses
Description-Content-Type: text/markdown

tagged_dataclasses
==================

Support for tagged unions based on dataclasses via a lightweight mixin that is supported
by mypy

```python
from typing import Optional

from dataclasses import dataclass

from tagged_dataclasses import TaggedUnion

class A:
    pass

@dataclass
class AB(A):
    pass

@dataclass
class AC(A):
    pass

@dataclass
class MyUnion(TaggedUnion[A]):
    # Optional is not optional here (this is for better support in PyCharm)
    first: Optional[AB] = None
    second: Optional[AC] = None

x = MyUnion.from_value(AB())

# support for many variations

if x.first is not None:
    pass
elif x.second is not None:
    pass

# other

if x.kind == AB:
    x.value()
elif x.kind == AC:
    x.value()



```

