enumerific 1.0.7__tar.gz → 1.0.9__tar.gz

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.
Files changed (23) hide show
  1. {enumerific-1.0.7/source/enumerific.egg-info → enumerific-1.0.9}/PKG-INFO +14 -4
  2. {enumerific-1.0.7 → enumerific-1.0.9}/README.md +13 -3
  3. {enumerific-1.0.7 → enumerific-1.0.9}/source/enumerific/extensible.py +36 -20
  4. enumerific-1.0.9/source/enumerific/version.txt +1 -0
  5. {enumerific-1.0.7 → enumerific-1.0.9/source/enumerific.egg-info}/PKG-INFO +14 -4
  6. {enumerific-1.0.7 → enumerific-1.0.9}/tests/test_extensible_enums.py +31 -6
  7. enumerific-1.0.7/source/enumerific/version.txt +0 -1
  8. {enumerific-1.0.7 → enumerific-1.0.9}/LICENSE.md +0 -0
  9. {enumerific-1.0.7 → enumerific-1.0.9}/pyproject.toml +0 -0
  10. {enumerific-1.0.7 → enumerific-1.0.9}/requirements.development.txt +0 -0
  11. {enumerific-1.0.7 → enumerific-1.0.9}/requirements.distribution.txt +0 -0
  12. {enumerific-1.0.7 → enumerific-1.0.9}/requirements.txt +0 -0
  13. {enumerific-1.0.7 → enumerific-1.0.9}/setup.cfg +0 -0
  14. {enumerific-1.0.7 → enumerific-1.0.9}/source/enumerific/__init__.py +0 -0
  15. {enumerific-1.0.7 → enumerific-1.0.9}/source/enumerific/exceptions.py +0 -0
  16. {enumerific-1.0.7 → enumerific-1.0.9}/source/enumerific/logging.py +0 -0
  17. {enumerific-1.0.7 → enumerific-1.0.9}/source/enumerific/standard.py +0 -0
  18. {enumerific-1.0.7 → enumerific-1.0.9}/source/enumerific.egg-info/SOURCES.txt +0 -0
  19. {enumerific-1.0.7 → enumerific-1.0.9}/source/enumerific.egg-info/dependency_links.txt +0 -0
  20. {enumerific-1.0.7 → enumerific-1.0.9}/source/enumerific.egg-info/requires.txt +0 -0
  21. {enumerific-1.0.7 → enumerific-1.0.9}/source/enumerific.egg-info/top_level.txt +0 -0
  22. {enumerific-1.0.7 → enumerific-1.0.9}/source/enumerific.egg-info/zip-safe +0 -0
  23. {enumerific-1.0.7 → enumerific-1.0.9}/tests/test_enumerific_library.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: enumerific
3
- Version: 1.0.7
3
+ Version: 1.0.9
4
4
  Summary: Simplifies working with Python enums.
5
5
  Author: Daniel Sissman
6
6
  License-Expression: MIT
@@ -690,8 +690,8 @@ class Colors(Enumeration):
690
690
  # Ensure that the Colors enumeration subclass is of the expected types
691
691
  assert issubclass(Colors, Enumeration)
692
692
 
693
- # Attempt to reconcile a Color against one of its annotations
694
- color = Colors.reconcile(value=(255, 0, 0), annotation="RGB")
693
+ # Attempt to reconcile a Color against one of its annotations (via annotation keyword)
694
+ color = Colors.reconcile(RGB=(255, 0, 0))
695
695
 
696
696
  assert isinstance(color, Colors)
697
697
  assert isinstance(color, Enumeration)
@@ -699,6 +699,16 @@ assert isinstance(color, Enumeration)
699
699
  assert color.name == "RED"
700
700
  assert color.value == 1
701
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)
702
712
  ```
703
713
 
704
714
  # Enumerific Library Enumerations: Classes & Methods
@@ -890,4 +900,4 @@ See the documentation for [PyTest](https://docs.pytest.org/en/latest/) regarding
890
900
 
891
901
  ### Copyright & License Information
892
902
 
893
- Copyright © 2024–2025 Daniel Sissman; licensed under the MIT License.
903
+ Copyright © 2024–2026 Daniel Sissman; licensed under the MIT License.
@@ -660,8 +660,8 @@ class Colors(Enumeration):
660
660
  # Ensure that the Colors enumeration subclass is of the expected types
661
661
  assert issubclass(Colors, Enumeration)
662
662
 
663
- # Attempt to reconcile a Color against one of its annotations
664
- color = Colors.reconcile(value=(255, 0, 0), annotation="RGB")
663
+ # Attempt to reconcile a Color against one of its annotations (via annotation keyword)
664
+ color = Colors.reconcile(RGB=(255, 0, 0))
665
665
 
666
666
  assert isinstance(color, Colors)
667
667
  assert isinstance(color, Enumeration)
@@ -669,6 +669,16 @@ assert isinstance(color, Enumeration)
669
669
  assert color.name == "RED"
670
670
  assert color.value == 1
671
671
  assert color.RGB == (255, 0, 0)
672
+
673
+ # Attempt to reconcile a Color against one of its annotations (via annotation argument)
674
+ color = Colors.reconcile(value=(0, 255, 0), annotation="RGB")
675
+
676
+ assert isinstance(color, Colors)
677
+ assert isinstance(color, Enumeration)
678
+
679
+ assert color.name == "GREEN"
680
+ assert color.value == 2
681
+ assert color.RGB == (0, 255, 0)
672
682
  ```
673
683
 
674
684
  # Enumerific Library Enumerations: Classes & Methods
@@ -860,4 +870,4 @@ See the documentation for [PyTest](https://docs.pytest.org/en/latest/) regarding
860
870
 
861
871
  ### Copyright & License Information
862
872
 
863
- Copyright © 2024–2025 Daniel Sissman; licensed under the MIT License.
873
+ Copyright © 2024–2026 Daniel Sissman; licensed under the MIT License.
@@ -90,6 +90,7 @@ class auto(int, anno):
90
90
 
91
91
  start: int = 0
92
92
  steps: int = 1
93
+ times: int = 0
93
94
  power: int = 0
94
95
  value: int = 0
95
96
 
@@ -1378,7 +1379,7 @@ class EnumerationMetaClass(type):
1378
1379
 
1379
1380
  return self._instance.__name__
1380
1381
 
1381
- def register(self, name: str, value: object) -> Enumeration:
1382
+ def register(self, name: str, value: object = auto()) -> Enumeration:
1382
1383
  """The 'register' method supports registering additional enumeration options for
1383
1384
  an existing enumeration class. The method accepts the name of the enumeration
1384
1385
  option and its corresponding value; these are then mapped into a new enumeration
@@ -1459,44 +1460,59 @@ class EnumerationMetaClass(type):
1459
1460
  name: str = None,
1460
1461
  caselessly: bool = False,
1461
1462
  annotation: str = None,
1463
+ **annotations: dict[str, object],
1462
1464
  ) -> Enumeration | None:
1463
1465
  """The 'reconcile' method can be used to reconcile Enumeration type, enumeration
1464
1466
  values, or enumeration names to their matching Enumeration type instances. If a
1465
1467
  match is found the Enumeration type instance will be returned otherwise None will
1466
1468
  be returned, unless the class is configured to raise an error for mismatches."""
1467
1469
 
1468
- if name is None and value is None:
1470
+ if isinstance(annotation, str):
1471
+ annotations[annotation] = value
1472
+
1473
+ if name is None and value is None and len(annotations) == 0:
1469
1474
  raise ValueError(
1470
- "Either the 'value' or 'name' argument must be specified when calling the 'reconcile' function!"
1475
+ "Either a 'value', 'name' or annotation keyword argument must be specified when calling the 'reconcile' function!"
1471
1476
  )
1472
1477
 
1473
1478
  if not value is None and not isinstance(value, (Enumeration, object)):
1474
1479
  raise TypeError(
1475
- "The 'value' argument must reference an Enumeration type or have an enumeration value!"
1480
+ "The 'value' argument, if specified, must reference an Enumeration type or have an enumeration value!"
1476
1481
  )
1477
1482
 
1478
1483
  if not name is None and not isinstance(name, str):
1479
- raise TypeError("The 'name' argument must have a string value!")
1484
+ raise TypeError(
1485
+ "The 'name' argument, if specified, must have a string value!"
1486
+ )
1480
1487
 
1481
1488
  reconciled: Enumeration = None
1482
1489
 
1483
1490
  for attribute, enumeration in self._enumerations.items():
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,
1491
+ if len(annotations) > 0:
1492
+ comparisons: list[bool] = []
1493
+
1494
+ for annotation, value in annotations.items():
1495
+ if annotation in enumeration._annotations:
1496
+ if enumeration._annotations[annotation] is value:
1497
+ comparisons.append(True)
1498
+ elif enumeration._annotations[annotation] == value:
1499
+ comparisons.append(True)
1500
+ else:
1501
+ comparisons.append(False)
1502
+ else:
1503
+ comparisons.append(False)
1504
+
1505
+ logger.debug(
1506
+ "The enumeration option, %s, has no '%s' annotation!"
1507
+ % (
1508
+ enumeration,
1509
+ annotation,
1510
+ )
1498
1511
  )
1499
- )
1512
+
1513
+ if len(comparisons) == len(annotations) and False not in comparisons:
1514
+ reconciled = enumeration
1515
+ break
1500
1516
  elif isinstance(value, Enumeration):
1501
1517
  if enumeration is value:
1502
1518
  reconciled = enumeration
@@ -0,0 +1 @@
1
+ 1.0.9
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: enumerific
3
- Version: 1.0.7
3
+ Version: 1.0.9
4
4
  Summary: Simplifies working with Python enums.
5
5
  Author: Daniel Sissman
6
6
  License-Expression: MIT
@@ -690,8 +690,8 @@ class Colors(Enumeration):
690
690
  # Ensure that the Colors enumeration subclass is of the expected types
691
691
  assert issubclass(Colors, Enumeration)
692
692
 
693
- # Attempt to reconcile a Color against one of its annotations
694
- color = Colors.reconcile(value=(255, 0, 0), annotation="RGB")
693
+ # Attempt to reconcile a Color against one of its annotations (via annotation keyword)
694
+ color = Colors.reconcile(RGB=(255, 0, 0))
695
695
 
696
696
  assert isinstance(color, Colors)
697
697
  assert isinstance(color, Enumeration)
@@ -699,6 +699,16 @@ assert isinstance(color, Enumeration)
699
699
  assert color.name == "RED"
700
700
  assert color.value == 1
701
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)
702
712
  ```
703
713
 
704
714
  # Enumerific Library Enumerations: Classes & Methods
@@ -890,4 +900,4 @@ See the documentation for [PyTest](https://docs.pytest.org/en/latest/) regarding
890
900
 
891
901
  ### Copyright & License Information
892
902
 
893
- Copyright © 2024–2025 Daniel Sissman; licensed under the MIT License.
903
+ Copyright © 2024–2026 Daniel Sissman; licensed under the MIT License.
@@ -1820,24 +1820,49 @@ def test_annotation_reconciliation():
1820
1820
  class Colors(Enumeration):
1821
1821
  """Create a test Color enumeration based on the Enumeration class"""
1822
1822
 
1823
- RED = auto(RGB=(255, 0, 0))
1823
+ RED = auto(RGB=(255, 0, 0), primary=True)
1824
1824
  ORANGE = auto(RGB=(255, 165, 0))
1825
- YELLOW = auto(RGB=(255, 255, 0))
1825
+ YELLOW = auto(RGB=(255, 255, 0), primary=True)
1826
1826
  GREEN = auto(RGB=(0, 255, 0))
1827
- BLUE = auto(RGB=(0, 0, 255))
1827
+ BLUE = auto(RGB=(0, 0, 255), primary=True)
1828
1828
  VIOLET = auto(RGB=(255, 0, 255))
1829
1829
 
1830
1830
  # Ensure that the Colors enumeration subclass is of the expected types
1831
1831
  assert issubclass(Colors, Enumeration)
1832
1832
  assert issubclass(Colors, EnumerationInteger)
1833
1833
 
1834
- # Attempt to reconcile a Color against one of its annotations
1835
- color = Colors.reconcile(value=(255, 0, 0), annotation="RGB")
1834
+ # Attempt to reconcile a Color against one of its annotations (via annotation keyword)
1835
+ color = Colors.reconcile(RGB=(255, 0, 0))
1836
1836
 
1837
1837
  assert isinstance(color, Colors)
1838
1838
  assert isinstance(color, Enumeration)
1839
- assert isinstance(color, EnumerationInteger)
1840
1839
 
1841
1840
  assert color.name == "RED"
1842
1841
  assert color.value == 1
1843
1842
  assert color.RGB == (255, 0, 0)
1843
+
1844
+ # Attempt to reconcile a Color against two of its annotations (via annotation keywords)
1845
+ color = Colors.reconcile(RGB=(255, 255, 0), primary=True)
1846
+
1847
+ assert isinstance(color, Colors)
1848
+ assert isinstance(color, Enumeration)
1849
+
1850
+ assert color.name == "YELLOW"
1851
+ assert color.value == 3
1852
+ assert color.RGB == (255, 255, 0)
1853
+
1854
+ # Attempt to reconcile a Color against one of its annotations (via annotation argument)
1855
+ color = Colors.reconcile(value=(0, 255, 0), annotation="RGB")
1856
+
1857
+ assert isinstance(color, Colors)
1858
+ assert isinstance(color, Enumeration)
1859
+
1860
+ assert color.name == "GREEN"
1861
+ assert color.value == 4
1862
+ assert color.RGB == (0, 255, 0)
1863
+
1864
+ # Test reconciliation against a non-existent option
1865
+ color = Colors.reconcile(RGB=(125, 125, 125))
1866
+
1867
+ # Ensure the return value is None when a matching enumeration option cannot be found
1868
+ assert color is None
@@ -1 +0,0 @@
1
- 1.0.7
File without changes
File without changes
File without changes
File without changes