enumerific 1.0.6__py3-none-any.whl → 1.0.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- enumerific/extensible.py +37 -5
- enumerific/version.txt +1 -1
- {enumerific-1.0.6.dist-info → enumerific-1.0.8.dist-info}/METADATA +37 -1
- enumerific-1.0.8.dist-info/RECORD +12 -0
- enumerific-1.0.6.dist-info/RECORD +0 -12
- {enumerific-1.0.6.dist-info → enumerific-1.0.8.dist-info}/WHEEL +0 -0
- {enumerific-1.0.6.dist-info → enumerific-1.0.8.dist-info}/licenses/LICENSE.md +0 -0
- {enumerific-1.0.6.dist-info → enumerific-1.0.8.dist-info}/top_level.txt +0 -0
- {enumerific-1.0.6.dist-info → enumerific-1.0.8.dist-info}/zip-safe +0 -0
enumerific/extensible.py
CHANGED
|
@@ -1458,29 +1458,61 @@ class EnumerationMetaClass(type):
|
|
|
1458
1458
|
value: Enumeration | object = None,
|
|
1459
1459
|
name: str = None,
|
|
1460
1460
|
caselessly: bool = False,
|
|
1461
|
+
annotation: str = None,
|
|
1462
|
+
**annotations: dict[str, object],
|
|
1461
1463
|
) -> Enumeration | None:
|
|
1462
1464
|
"""The 'reconcile' method can be used to reconcile Enumeration type, enumeration
|
|
1463
1465
|
values, or enumeration names to their matching Enumeration type instances. If a
|
|
1464
1466
|
match is found the Enumeration type instance will be returned otherwise None will
|
|
1465
1467
|
be returned, unless the class is configured to raise an error for mismatches."""
|
|
1466
1468
|
|
|
1467
|
-
if
|
|
1469
|
+
if isinstance(annotation, str):
|
|
1470
|
+
annotations[annotation] = value
|
|
1471
|
+
|
|
1472
|
+
if name is None and value is None and len(annotations) == 0:
|
|
1468
1473
|
raise ValueError(
|
|
1469
|
-
"Either
|
|
1474
|
+
"Either a 'value', 'name' or annotation keyword argument must be specified when calling the 'reconcile' function!"
|
|
1470
1475
|
)
|
|
1471
1476
|
|
|
1472
1477
|
if not value is None and not isinstance(value, (Enumeration, object)):
|
|
1473
1478
|
raise TypeError(
|
|
1474
|
-
"The 'value' argument must reference an Enumeration type or have an enumeration value!"
|
|
1479
|
+
"The 'value' argument, if specified, must reference an Enumeration type or have an enumeration value!"
|
|
1475
1480
|
)
|
|
1476
1481
|
|
|
1477
1482
|
if not name is None and not isinstance(name, str):
|
|
1478
|
-
raise TypeError(
|
|
1483
|
+
raise TypeError(
|
|
1484
|
+
"The 'name' argument, if specified, must have a string value!"
|
|
1485
|
+
)
|
|
1479
1486
|
|
|
1480
1487
|
reconciled: Enumeration = None
|
|
1481
1488
|
|
|
1482
1489
|
for attribute, enumeration in self._enumerations.items():
|
|
1483
|
-
if
|
|
1490
|
+
if len(annotations) > 0:
|
|
1491
|
+
comparisons: list[bool] = []
|
|
1492
|
+
|
|
1493
|
+
for annotation, value in annotations.items():
|
|
1494
|
+
if annotation in enumeration._annotations:
|
|
1495
|
+
if enumeration._annotations[annotation] is value:
|
|
1496
|
+
comparisons.append(True)
|
|
1497
|
+
elif enumeration._annotations[annotation] == value:
|
|
1498
|
+
comparisons.append(True)
|
|
1499
|
+
else:
|
|
1500
|
+
comparisons.append(False)
|
|
1501
|
+
else:
|
|
1502
|
+
comparisons.append(False)
|
|
1503
|
+
|
|
1504
|
+
logger.debug(
|
|
1505
|
+
"The enumeration option, %s, has no '%s' annotation!"
|
|
1506
|
+
% (
|
|
1507
|
+
enumeration,
|
|
1508
|
+
annotation,
|
|
1509
|
+
)
|
|
1510
|
+
)
|
|
1511
|
+
|
|
1512
|
+
if len(comparisons) == len(annotations) and False not in comparisons:
|
|
1513
|
+
reconciled = enumeration
|
|
1514
|
+
break
|
|
1515
|
+
elif isinstance(value, Enumeration):
|
|
1484
1516
|
if enumeration is value:
|
|
1485
1517
|
reconciled = enumeration
|
|
1486
1518
|
break
|
enumerific/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0.
|
|
1
|
+
1.0.8
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: enumerific
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.8
|
|
4
4
|
Summary: Simplifies working with Python enums.
|
|
5
5
|
Author: Daniel Sissman
|
|
6
6
|
License-Expression: MIT
|
|
@@ -675,6 +675,42 @@ assert Colors.PURPLE.rgb == (255, 0, 255)
|
|
|
675
675
|
assert Colors.PURPLE.primary is False
|
|
676
676
|
```
|
|
677
677
|
|
|
678
|
+
#### Example 19: Reconciling Enumeration Options via Annotations
|
|
679
|
+
|
|
680
|
+
```python
|
|
681
|
+
from enumerific import Enumeration, auto
|
|
682
|
+
|
|
683
|
+
class Colors(Enumeration):
|
|
684
|
+
"""Create a test Color enumeration based on the Enumeration class"""
|
|
685
|
+
|
|
686
|
+
RED = auto(RGB=(255, 0, 0))
|
|
687
|
+
GREEN = auto(RGB=(0, 255, 0))
|
|
688
|
+
BLUE = auto(RGB=(0, 0, 255))
|
|
689
|
+
|
|
690
|
+
# Ensure that the Colors enumeration subclass is of the expected types
|
|
691
|
+
assert issubclass(Colors, Enumeration)
|
|
692
|
+
|
|
693
|
+
# Attempt to reconcile a Color against one of its annotations (via annotation keyword)
|
|
694
|
+
color = Colors.reconcile(RGB=(255, 0, 0))
|
|
695
|
+
|
|
696
|
+
assert isinstance(color, Colors)
|
|
697
|
+
assert isinstance(color, Enumeration)
|
|
698
|
+
|
|
699
|
+
assert color.name == "RED"
|
|
700
|
+
assert color.value == 1
|
|
701
|
+
assert color.RGB == (255, 0, 0)
|
|
702
|
+
|
|
703
|
+
# Attempt to reconcile a Color against one of its annotations (via annotation argument)
|
|
704
|
+
color = Colors.reconcile(value=(0, 255, 0), annotation="RGB")
|
|
705
|
+
|
|
706
|
+
assert isinstance(color, Colors)
|
|
707
|
+
assert isinstance(color, Enumeration)
|
|
708
|
+
|
|
709
|
+
assert color.name == "GREEN"
|
|
710
|
+
assert color.value == 2
|
|
711
|
+
assert color.RGB == (0, 255, 0)
|
|
712
|
+
```
|
|
713
|
+
|
|
678
714
|
# Enumerific Library Enumerations: Classes & Methods
|
|
679
715
|
|
|
680
716
|
The Enumerific library's `Enumeration` class is a greenfield implementation of enumerations
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
enumerific/__init__.py,sha256=K9iFirgxSkrHgXfhocOvgRkskGe0VfWRgxEvppnVWBM,587
|
|
2
|
+
enumerific/exceptions.py,sha256=lvfcH1cz43hDjzSUpgm1-OZjKzxo--fyZ8UsBS-GiZA,359
|
|
3
|
+
enumerific/extensible.py,sha256=o0n9PdgnbC52vw4wbk4kUkmRsFUTN_e7yqe7LA-6Obg,87108
|
|
4
|
+
enumerific/logging.py,sha256=zz1Phnot1BFWMoxwvZ0FlZDsiYZZYhz-_S4IzgPYc40,97
|
|
5
|
+
enumerific/standard.py,sha256=xQhhwlcYZ6-8DmgscbV38g2Ol5Z8_vvBwonz-Ww0I40,3254
|
|
6
|
+
enumerific/version.txt,sha256=phVSvZad-OqKy8Q8pyiMu01dODZaYQyAIaQn4mpRhR0,5
|
|
7
|
+
enumerific-1.0.8.dist-info/licenses/LICENSE.md,sha256=j1XidOCGUhPx7CyXA31uC0XGKDRnvUcZpMp161qHI6g,1077
|
|
8
|
+
enumerific-1.0.8.dist-info/METADATA,sha256=Loee454XK_bhrv_N3PKAEFjDFHATJBQbdG4QZRGzLYg,34237
|
|
9
|
+
enumerific-1.0.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
enumerific-1.0.8.dist-info/top_level.txt,sha256=hyemsMgPYZgSx71XHmFRF-gvc_2Y4rDAESR8e0hbYHU,11
|
|
11
|
+
enumerific-1.0.8.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
12
|
+
enumerific-1.0.8.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
enumerific/__init__.py,sha256=K9iFirgxSkrHgXfhocOvgRkskGe0VfWRgxEvppnVWBM,587
|
|
2
|
-
enumerific/exceptions.py,sha256=lvfcH1cz43hDjzSUpgm1-OZjKzxo--fyZ8UsBS-GiZA,359
|
|
3
|
-
enumerific/extensible.py,sha256=9OodW6krNAd2B85QesBNUl3T5tcfsEJf_UhZ5sbNvyE,85763
|
|
4
|
-
enumerific/logging.py,sha256=zz1Phnot1BFWMoxwvZ0FlZDsiYZZYhz-_S4IzgPYc40,97
|
|
5
|
-
enumerific/standard.py,sha256=xQhhwlcYZ6-8DmgscbV38g2Ol5Z8_vvBwonz-Ww0I40,3254
|
|
6
|
-
enumerific/version.txt,sha256=4ct5uLutDTkkmV0uFpcf40QM4kZNWdiGBJJcDWsLbF0,5
|
|
7
|
-
enumerific-1.0.6.dist-info/licenses/LICENSE.md,sha256=j1XidOCGUhPx7CyXA31uC0XGKDRnvUcZpMp161qHI6g,1077
|
|
8
|
-
enumerific-1.0.6.dist-info/METADATA,sha256=DgcRl0DM_TlaRkBg7fIaMBl4wfKUydvjIzYsgLFJpL4,33208
|
|
9
|
-
enumerific-1.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
-
enumerific-1.0.6.dist-info/top_level.txt,sha256=hyemsMgPYZgSx71XHmFRF-gvc_2Y4rDAESR8e0hbYHU,11
|
|
11
|
-
enumerific-1.0.6.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
12
|
-
enumerific-1.0.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|