abs-utils 0.2.1__tar.gz → 0.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: abs-utils
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: AutoBridge Systems Utility Library
5
5
  Author: AutoBridgeSystems
6
6
  Author-email: info@autobridgesystems.com
@@ -0,0 +1,28 @@
1
+ from enum import Enum
2
+ from typing import Type, Union, Dict
3
+
4
+
5
+ def extend_enum(
6
+ name: str,
7
+ base_enum: Type[Enum],
8
+ additional_fields: Union[Dict[str, str], Type[Enum]]
9
+ ) -> Type[Enum]:
10
+ """
11
+ Create a new Enum by extending an existing one with additional fields
12
+ provided either as a dict or another Enum class.
13
+
14
+ :param name: Name of the new Enum
15
+ :param base_enum: The base Enum class to extend
16
+ :param additional_fields: A dict or Enum class with new values
17
+ :return: A new Enum class with combined values
18
+ """
19
+ base_members = {e.name: e.value for e in base_enum}
20
+ extra_members = {}
21
+ if isinstance(additional_fields, dict):
22
+ extra_members = additional_fields
23
+ elif isinstance(additional_fields, type) and issubclass(additional_fields, Enum):
24
+ extra_members = {e.name: e.value for e in additional_fields}
25
+
26
+ merged_members = {**base_members, **extra_members}
27
+
28
+ return Enum(name, merged_members, type=str)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "abs-utils"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  description = "AutoBridge Systems Utility Library"
5
5
  authors = [
6
6
  {name = "AutoBridgeSystems", email = "info@autobridgesystems.com"}
File without changes