Skip to main content

Enum Algebraic Data Types (ADTs) for Python

Project description

enum-adt

Enum Algebraic Data Types (ADTs) for Python.

Installation

Run the following command to install the Python package on Python 3.8 or later:

pip install enum-adt

Or you can simply copy the enum_adt.py file anywhere in your project.

Usage

from enum_adt import ADT

class MyEnum(ADT):
    class Foo: ...

    class Bar:
        name: str

foo = MyEnum.Foo()
bar = MyEnum.Bar("bar")
assert isinstance(foo, MyEnum)
assert isinstance(bar, MyEnum)

Alternatively, you can use metaclass:

from enum_adt import ADTMeta

class MyEnum(metaclass=ADTMeta):
    class Foo: ...

    class Bar:
        name: str

Each internal class will be created as a dataclass with the same attributes. You can customize the dataclass by passing arguments to the class:

All enum variants get the same arguments.

from enum_adt import ADT

class MyEnum(ADT, frozen=True, kw_only=True):
    class Foo: ...

    class Bar:
        name: str

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

enum_adt-0.0.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

enum_adt-0.0.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file enum_adt-0.0.1.tar.gz.

File metadata

  • Download URL: enum_adt-0.0.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.16.0 CPython/3.11.9 Darwin/23.5.0

File hashes

Hashes for enum_adt-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0a46137d7f10ddad4bff2a5867cd531155d1bf08aa706d3498088bd6b50dea8b
MD5 663a389dde698bfa8760068e31c49020
BLAKE2b-256 1f5c8a8c2f1cf50763edf5b4e186e23325e7fb302302c26381c259ff13487812

See more details on using hashes here.

File details

Details for the file enum_adt-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: enum_adt-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.16.0 CPython/3.11.9 Darwin/23.5.0

File hashes

Hashes for enum_adt-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d697442cd4d2ee6e1ef2b2e1ffaa2d1a3024ddefac2bd06c4971446a6db0da2
MD5 699d7c1039122be5bfadd7bfb43c0c7f
BLAKE2b-256 0ca5d4cb9d060c4dad7cc06842663f60189f27397e5ee3a745827a79062e108f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page