kkpyutil 1.42.0__tar.gz → 1.43.0__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.1
2
2
  Name: kkpyutil
3
- Version: 1.42.0
3
+ Version: 1.43.0
4
4
  Summary: Building blocks for sysadmin and DevOps
5
5
  Home-page: https://github.com/kakyoism/kkpyutil/
6
6
  License: MIT
@@ -105,6 +105,18 @@ class ClassicSingleton:
105
105
  raise RuntimeError("Use `cls.instance()` to access the singleton instance.")
106
106
 
107
107
 
108
+ class MetaSingleton(type):
109
+ """
110
+ - usage: class MyClass(metaclass=MetaSingleton)
111
+ """
112
+ _instances = {}
113
+
114
+ def __call__(cls, *args, **kwargs):
115
+ if cls not in cls._instances:
116
+ cls._instances[cls] = super(MetaSingleton, cls).__call__(*args, **kwargs)
117
+ return cls._instances[cls]
118
+
119
+
108
120
  class BorgSingleton:
109
121
  """
110
122
  - Borg pattern: all instances share the same state, but not the same identity
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "kkpyutil"
3
- version = "1.42.0"
3
+ version = "1.43.0"
4
4
  description = "Building blocks for sysadmin and DevOps"
5
5
  authors = ["Beinan Li <li.beinan@gmail.com>"]
6
6
  maintainers = ["Beinan Li <li.beinan@gmail.com>"]
File without changes
File without changes