Skip to main content

tagged_dataclasses

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

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()

Release files for tagged-dataclasses 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tagged-dataclasses 0.0.2
File Size Uploaded
tagged_dataclasses-0.0.2.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tagged-dataclasses 0.0.2
File Interpreter ABI Platform
tagged_dataclasses-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size:6.3 kB

Release files / tagged_dataclasses-0.0.2.tar.gz

Download URL tagged_dataclasses-0.0.2.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6a08929387e3b04a0667f8457caf5a98a3ec5a904a4b2781c5c23fd006a1fbcb
BLAKE2b-256 checksum
How to use checksums
ac5499d2d17523ace3ff43b67b1e094080d272ccca14ed164ff4c845d26f8102
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

Release files / tagged_dataclasses-0.0.2-py3-none-any.whl

Download URL tagged_dataclasses-0.0.2-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04600afefe4befd668489753c6ebaf2c95ca348fce2092e01c87d45b046c8f0c
BLAKE2b-256 checksum
How to use checksums
164a1fcc18c0da12f6193043dac371bedcec4b06afc2b454e2a0622055ca76bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page