Skip to main content

set of enum.Enum

Project description

enumset

collection of Enum classes.

Install

  • pip install enumset

Enumset

Enumset stores multiple Enum-class value, each value in Enum-class should be unique.

from enum import Enum, Flag
from enumset import Enumset

A = Enum("A", "A1 A2 A3")
B = Enum("B", "B1 B2")
C = Flag("C", "C1 C2 C3 C4")

es = Enumset([A, B, C])
es.setval(A.A1)
es.setval(B.B2)
es.setval(C.C3)
assert list(es.values()) == [A.A1, B.B2, C.C3]
assert es.getval(A) == A.A1

es.setval(A.A2)   # replace A1 -> A2
es.setval(C.C4)   # replace C3 -> C4
assert list(es.values()) == [A.A2, B.B2, C.C4]
assert es.getval(A) == A.A2

Flagset

Flagset stores multiple Enum-class value, like set[Enum].

from enum import Enum, Flag
from enumset import Flagset

A = Enum("A", "A1 A2 A3")
B = Enum("B", "B1 B2")
C = Flag("C", "C1 C2 C3 C4")

fs = Flagset([A, B, C])
fs.setval(A.A1)
fs.setval(B.B2)
fs.setval(C.C3)
assert list(fs.values()) == [A.A1, B.B2, C.C3]
assert list(fs.getval(A)) == [A.A1]

fs.setval(A.A2)   # A1+A2
fs.setval(C.C4)   # C3+C4
assert list(fs.values()) == [A.A1, A.A2, B.B2, C.C3, C.C4]
assert list(fs.getval(A)) == [A.A1, A.A2]
assert list(fs.getval(C)) == [C.C3, C.C4]

fs.setval(A.A2)   # A2 already exists
assert list(fs.values()) == [A.A1, A.A2, B.B2, C.C3, C.C4]

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

enumset-0.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file enumset-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: enumset-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for enumset-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42c9a59785c397dc54f9b9c45241899a1a3266b1a9d6a83127f1ce0b06479d71
MD5 2353931cd232fb64ab5a3f80f3ae242d
BLAKE2b-256 c5f1787c69207455b5e2e5b15ed82a1e2e42ef661dba3bd78c4843fe193d83b0

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