enumerific 1.0.5__py3-none-any.whl → 1.0.7__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 CHANGED
@@ -1458,6 +1458,7 @@ class EnumerationMetaClass(type):
1458
1458
  value: Enumeration | object = None,
1459
1459
  name: str = None,
1460
1460
  caselessly: bool = False,
1461
+ annotation: str = None,
1461
1462
  ) -> Enumeration | None:
1462
1463
  """The 'reconcile' method can be used to reconcile Enumeration type, enumeration
1463
1464
  values, or enumeration names to their matching Enumeration type instances. If a
@@ -1480,7 +1481,23 @@ class EnumerationMetaClass(type):
1480
1481
  reconciled: Enumeration = None
1481
1482
 
1482
1483
  for attribute, enumeration in self._enumerations.items():
1483
- if isinstance(value, Enumeration):
1484
+ if isinstance(annotation, str):
1485
+ if annotation in enumeration._annotations:
1486
+ if enumeration._annotations[annotation] is value:
1487
+ reconciled = enumeration
1488
+ break
1489
+ elif enumeration._annotations[annotation] == value:
1490
+ reconciled = enumeration
1491
+ break
1492
+ else:
1493
+ raise EnumerationOptionError(
1494
+ "The enumeration option, %s, has no '%s' annotation!"
1495
+ % (
1496
+ enumeration,
1497
+ annotation,
1498
+ )
1499
+ )
1500
+ elif isinstance(value, Enumeration):
1484
1501
  if enumeration is value:
1485
1502
  reconciled = enumeration
1486
1503
  break
@@ -1797,6 +1814,28 @@ class Enumeration(metaclass=EnumerationMetaClass):
1797
1814
 
1798
1815
  return aliases
1799
1816
 
1817
+ @property
1818
+ def named(self) -> list[str]:
1819
+ logger.debug(
1820
+ "%s.names() >>> id(%s) => %s (%s)",
1821
+ self.__class__.__name__,
1822
+ self,
1823
+ id(self._enumerations),
1824
+ type(self._enumerations),
1825
+ )
1826
+
1827
+ names: list[Enumeration] = [self.name]
1828
+
1829
+ for name, enumeration in self._enumerations.items():
1830
+ logger.debug(" >>> checking for alias: %s => %s", name, enumeration)
1831
+
1832
+ if isinstance(enumeration, Enumeration):
1833
+ if self is enumeration and enumeration.name != name:
1834
+ if not name in names:
1835
+ names.append(name)
1836
+
1837
+ return names
1838
+
1800
1839
 
1801
1840
  class EnumerationType(Enumeration, typecast=False):
1802
1841
  """The EnumerationType class represents the type of value held by an enumeration."""
enumerific/version.txt CHANGED
@@ -1 +1 @@
1
- 1.0.5
1
+ 1.0.7
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: enumerific
3
- Version: 1.0.5
3
+ Version: 1.0.7
4
4
  Summary: Simplifies working with Python enums.
5
5
  Author: Daniel Sissman
6
6
  License-Expression: MIT
@@ -468,6 +468,11 @@ assert Colors.BLUE.aliased is False
468
468
  assert Colors.RED.aliases == [Colors.ROUGE]
469
469
  assert Colors.GREEN.aliases == [Colors.VERTE]
470
470
  assert Colors.BLUE.aliases == [] # BLUE has not been aliased
471
+
472
+ # The names including any aliases for an option can be obtained via the .named property
473
+ assert Colors.RED.named == ["RED", "ROUGE"]
474
+ assert Colors.GREEN.named == ["GREEN", "VERTE"]
475
+ assert Colors.BLUE.named == ["BLUE"]
471
476
  ```
472
477
 
473
478
  #### Example 15: Non-Unique Options
@@ -670,6 +675,32 @@ assert Colors.PURPLE.rgb == (255, 0, 255)
670
675
  assert Colors.PURPLE.primary is False
671
676
  ```
672
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
694
+ color = Colors.reconcile(value=(255, 0, 0), annotation="RGB")
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
+
673
704
  # Enumerific Library Enumerations: Classes & Methods
674
705
 
675
706
  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=HX-oZ91XtTLk5dmlqFOSFCO71_TEj1zGaO4KSKGwwoY,86507
4
+ enumerific/logging.py,sha256=zz1Phnot1BFWMoxwvZ0FlZDsiYZZYhz-_S4IzgPYc40,97
5
+ enumerific/standard.py,sha256=xQhhwlcYZ6-8DmgscbV38g2Ol5Z8_vvBwonz-Ww0I40,3254
6
+ enumerific/version.txt,sha256=6fmB8RVMkjgdY7ZTz7_Hm-ksP2zJXgkVpeXBnzkkylg,5
7
+ enumerific-1.0.7.dist-info/licenses/LICENSE.md,sha256=j1XidOCGUhPx7CyXA31uC0XGKDRnvUcZpMp161qHI6g,1077
8
+ enumerific-1.0.7.dist-info/METADATA,sha256=AnTj6l-xLoVxh1rQ1dFw1t8_v3Aq2slvwgiL458SBGs,33923
9
+ enumerific-1.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ enumerific-1.0.7.dist-info/top_level.txt,sha256=hyemsMgPYZgSx71XHmFRF-gvc_2Y4rDAESR8e0hbYHU,11
11
+ enumerific-1.0.7.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
12
+ enumerific-1.0.7.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=W-W1wXCW1wE7PP3Y2qbhxLpD2ETjmIQ-QTGnWIEGUyg,85084
4
- enumerific/logging.py,sha256=zz1Phnot1BFWMoxwvZ0FlZDsiYZZYhz-_S4IzgPYc40,97
5
- enumerific/standard.py,sha256=xQhhwlcYZ6-8DmgscbV38g2Ol5Z8_vvBwonz-Ww0I40,3254
6
- enumerific/version.txt,sha256=nXE_EpedYoeSULwKIDXj71cxWsQlHoUBnSHHXtcmlyA,5
7
- enumerific-1.0.5.dist-info/licenses/LICENSE.md,sha256=j1XidOCGUhPx7CyXA31uC0XGKDRnvUcZpMp161qHI6g,1077
8
- enumerific-1.0.5.dist-info/METADATA,sha256=WDWq40qr1A3IHSTMDVOfUcCw76YCUnlEqxcRKPI4rRU,32990
9
- enumerific-1.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- enumerific-1.0.5.dist-info/top_level.txt,sha256=hyemsMgPYZgSx71XHmFRF-gvc_2Y4rDAESR8e0hbYHU,11
11
- enumerific-1.0.5.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
12
- enumerific-1.0.5.dist-info/RECORD,,