enumerific 1.0.4__tar.gz → 1.0.6__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.4/source/enumerific.egg-info → enumerific-1.0.6}/PKG-INFO +6 -1
  2. {enumerific-1.0.4 → enumerific-1.0.6}/README.md +5 -0
  3. {enumerific-1.0.4 → enumerific-1.0.6}/source/enumerific/extensible.py +30 -4
  4. enumerific-1.0.6/source/enumerific/version.txt +1 -0
  5. {enumerific-1.0.4 → enumerific-1.0.6/source/enumerific.egg-info}/PKG-INFO +6 -1
  6. {enumerific-1.0.4 → enumerific-1.0.6}/tests/test_extensible_enums.py +37 -4
  7. enumerific-1.0.4/source/enumerific/version.txt +0 -1
  8. {enumerific-1.0.4 → enumerific-1.0.6}/LICENSE.md +0 -0
  9. {enumerific-1.0.4 → enumerific-1.0.6}/pyproject.toml +0 -0
  10. {enumerific-1.0.4 → enumerific-1.0.6}/requirements.development.txt +0 -0
  11. {enumerific-1.0.4 → enumerific-1.0.6}/requirements.distribution.txt +0 -0
  12. {enumerific-1.0.4 → enumerific-1.0.6}/requirements.txt +0 -0
  13. {enumerific-1.0.4 → enumerific-1.0.6}/setup.cfg +0 -0
  14. {enumerific-1.0.4 → enumerific-1.0.6}/source/enumerific/__init__.py +0 -0
  15. {enumerific-1.0.4 → enumerific-1.0.6}/source/enumerific/exceptions.py +0 -0
  16. {enumerific-1.0.4 → enumerific-1.0.6}/source/enumerific/logging.py +0 -0
  17. {enumerific-1.0.4 → enumerific-1.0.6}/source/enumerific/standard.py +0 -0
  18. {enumerific-1.0.4 → enumerific-1.0.6}/source/enumerific.egg-info/SOURCES.txt +0 -0
  19. {enumerific-1.0.4 → enumerific-1.0.6}/source/enumerific.egg-info/dependency_links.txt +0 -0
  20. {enumerific-1.0.4 → enumerific-1.0.6}/source/enumerific.egg-info/requires.txt +0 -0
  21. {enumerific-1.0.4 → enumerific-1.0.6}/source/enumerific.egg-info/top_level.txt +0 -0
  22. {enumerific-1.0.4 → enumerific-1.0.6}/source/enumerific.egg-info/zip-safe +0 -0
  23. {enumerific-1.0.4 → enumerific-1.0.6}/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.4
3
+ Version: 1.0.6
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
@@ -438,6 +438,11 @@ assert Colors.BLUE.aliased is False
438
438
  assert Colors.RED.aliases == [Colors.ROUGE]
439
439
  assert Colors.GREEN.aliases == [Colors.VERTE]
440
440
  assert Colors.BLUE.aliases == [] # BLUE has not been aliased
441
+
442
+ # The names including any aliases for an option can be obtained via the .named property
443
+ assert Colors.RED.named == ["RED", "ROUGE"]
444
+ assert Colors.GREEN.named == ["GREEN", "VERTE"]
445
+ assert Colors.BLUE.named == ["BLUE"]
441
446
  ```
442
447
 
443
448
  #### Example 15: Non-Unique Options
@@ -1195,7 +1195,7 @@ class EnumerationMetaClass(type):
1195
1195
 
1196
1196
  logger.debug("+" * 100)
1197
1197
 
1198
- def __getattr__(self, name) -> object:
1198
+ def __getattr__(self, name: str) -> object:
1199
1199
  # logger.debug("%s.__getattr__(name: %s)", self.__class__.__name__, name)
1200
1200
 
1201
1201
  if name.startswith("_") or name in self._special:
@@ -1651,7 +1651,7 @@ class Enumeration(metaclass=EnumerationMetaClass):
1651
1651
  )
1652
1652
 
1653
1653
  if annotations is None:
1654
- pass
1654
+ self._annotations = anno(value=self.value)
1655
1655
  elif isinstance(annotations, anno):
1656
1656
  self._annotations = annotations
1657
1657
  else:
@@ -1704,8 +1704,6 @@ class Enumeration(metaclass=EnumerationMetaClass):
1704
1704
  return object.__getattribute__(self, name)
1705
1705
  elif self._enumerations and name in self._enumerations:
1706
1706
  return self._enumerations[name]
1707
- elif self._annotations and name in self._annotations:
1708
- return self._annotations[name]
1709
1707
  elif self._context and name in dir(self._context):
1710
1708
  # Handle class methods, instance methods and properties here; because we are
1711
1709
  # performing some special handling for enumerations, we need to reintroduce
@@ -1719,6 +1717,8 @@ class Enumeration(metaclass=EnumerationMetaClass):
1719
1717
  return attribute.__get__(self)
1720
1718
  else:
1721
1719
  return attribute
1720
+ elif self._annotations and name in self._annotations:
1721
+ return self._annotations[name]
1722
1722
  else:
1723
1723
  # EnumerationOptionError subclasses AttributeError so we adhere to convention
1724
1724
  raise EnumerationOptionError(
@@ -1753,6 +1753,10 @@ class Enumeration(metaclass=EnumerationMetaClass):
1753
1753
  def value(self) -> object:
1754
1754
  return self._value
1755
1755
 
1756
+ @property
1757
+ def annotations(self) -> anno:
1758
+ return self._annotations
1759
+
1756
1760
  @property
1757
1761
  def aliased(self) -> bool:
1758
1762
  logger.debug(
@@ -1793,6 +1797,28 @@ class Enumeration(metaclass=EnumerationMetaClass):
1793
1797
 
1794
1798
  return aliases
1795
1799
 
1800
+ @property
1801
+ def named(self) -> list[str]:
1802
+ logger.debug(
1803
+ "%s.names() >>> id(%s) => %s (%s)",
1804
+ self.__class__.__name__,
1805
+ self,
1806
+ id(self._enumerations),
1807
+ type(self._enumerations),
1808
+ )
1809
+
1810
+ names: list[Enumeration] = [self.name]
1811
+
1812
+ for name, enumeration in self._enumerations.items():
1813
+ logger.debug(" >>> checking for alias: %s => %s", name, enumeration)
1814
+
1815
+ if isinstance(enumeration, Enumeration):
1816
+ if self is enumeration and enumeration.name != name:
1817
+ if not name in names:
1818
+ names.append(name)
1819
+
1820
+ return names
1821
+
1796
1822
 
1797
1823
  class EnumerationType(Enumeration, typecast=False):
1798
1824
  """The EnumerationType class represents the type of value held by an enumeration."""
@@ -0,0 +1 @@
1
+ 1.0.6
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: enumerific
3
- Version: 1.0.4
3
+ Version: 1.0.6
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
@@ -380,24 +380,57 @@ def test_extensible_enumeration_integer_non_unique():
380
380
  BLUE = 3
381
381
  ROUGE = 1
382
382
 
383
- assert (
384
- len(Colors) == 4
385
- ) # while there are only 3 distinct values, there are 4 options
383
+ # While there are only 3 distinct values, there are 4 options, due the alias for RED
384
+ assert len(Colors) == 4
386
385
 
387
- assert Colors.RED is Colors.ROUGE # as ROUGE is an alias of RED, identity matches
386
+ # Ensure that the keys, names, values, items and options methods return as expected
387
+ assert Colors.keys() == ["RED", "GREEN", "BLUE", "ROUGE"]
388
+ assert Colors.names() == ["RED", "GREEN", "BLUE", "ROUGE"]
389
+ assert Colors.values() == [1, 2, 3, 1]
390
+ assert Colors.items() == [("RED", 1), ("GREEN", 2), ("BLUE", 3), ("ROUGE", 1)]
391
+ assert Colors.options() == {"RED": 1, "GREEN": 2, "BLUE": 3, "ROUGE": 1}
388
392
 
393
+ # Ensure that the aliased option has the expected identity and equality
394
+ assert Colors.RED is Colors.ROUGE # As ROUGE is an alias of RED, identity matches
395
+ assert Colors.RED == Colors.ROUGE # As ROUGE is an alias of RED, equality matches
396
+
397
+ # Ensure that the property values of RED are as expected
389
398
  assert Colors.RED.name == "RED"
390
399
  assert Colors.RED.value == 1
400
+ assert Colors.RED.aliased is True
401
+ assert Colors.RED.aliases == [Colors.ROUGE]
402
+ assert Colors.RED.named == ["RED", "ROUGE"]
391
403
 
404
+ # Ensure that the property values of ROUGE are as expected (as an alias of RED)
392
405
  assert Colors.ROUGE.name == "RED"
393
406
  assert Colors.ROUGE.value == 1
407
+ assert Colors.ROUGE.aliased is True
408
+ assert Colors.ROUGE.aliases == [Colors.RED]
409
+ assert Colors.ROUGE.named == ["RED", "ROUGE"]
410
+
411
+ # Ensure that the property values of GREEN are as expected
412
+ assert Colors.GREEN.name == "GREEN"
413
+ assert Colors.GREEN.value == 2
414
+ assert Colors.GREEN.aliased is False
415
+ assert Colors.GREEN.aliases == []
416
+ assert Colors.GREEN.named == ["GREEN"]
417
+
418
+ # Ensure that the property values of BLUE are as expected
419
+ assert Colors.BLUE.name == "BLUE"
420
+ assert Colors.BLUE.value == 3
421
+ assert Colors.BLUE.aliased is False
422
+ assert Colors.BLUE.aliases == []
423
+ assert Colors.BLUE.named == ["BLUE"]
394
424
 
425
+ # We can find the aliases for the Colors enumeration by finding the options with
426
+ # names that do no match their associated enumeration option name:
395
427
  assert [
396
428
  name for name, option in Colors.__options__.items() if option.name != name
397
429
  ] == [
398
430
  "ROUGE"
399
431
  ] # ROUGE is an alias, so its name does not match the option it maps to
400
432
 
433
+ # Ensure that the aliases map is as expected
401
434
  assert len(Colors.__aliases__) == 1
402
435
  assert Colors.__aliases__ == {"ROUGE": Colors.RED}
403
436
  assert list(Colors.__aliases__.items()) == [("ROUGE", Colors.RED)]
@@ -1 +0,0 @@
1
- 1.0.4
File without changes
File without changes
File without changes
File without changes