aboutsummaryrefslogtreecommitdiff
path: root/tools/cru-py/cru/util/_const.py
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-11-11 01:12:29 +0800
committerYuqian Yang <crupest@crupest.life>2024-12-18 18:31:27 +0800
commiteff33fcbc8e78b1cd15332c229cd39ae9befbe5e (patch)
tree1c83d262c79a15a06b5a02ce3276af0e8130c513 /tools/cru-py/cru/util/_const.py
parentf35afa17a47fa8e0cafbff5956feab64adb503be (diff)
downloadcrupest-eff33fcbc8e78b1cd15332c229cd39ae9befbe5e.tar.gz
crupest-eff33fcbc8e78b1cd15332c229cd39ae9befbe5e.tar.bz2
crupest-eff33fcbc8e78b1cd15332c229cd39ae9befbe5e.zip
HALF WORK: 2024.11.11
Diffstat (limited to 'tools/cru-py/cru/util/_const.py')
-rw-r--r--tools/cru-py/cru/util/_const.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/cru-py/cru/util/_const.py b/tools/cru-py/cru/util/_const.py
new file mode 100644
index 0000000..ea67450
--- /dev/null
+++ b/tools/cru-py/cru/util/_const.py
@@ -0,0 +1,51 @@
+from typing import Any
+
+
+def make_unique_object() -> Any:
+ class _CruUnique:
+ _i = False
+
+ def __init__(self):
+ if self._i:
+ raise ValueError("_CruAttrNotSet is a singleton!")
+ self._i = True
+
+ def __copy__(self):
+ return self
+
+ def __eq__(self, other):
+ return isinstance(other, _CruUnique)
+
+ v = _CruUnique()
+
+ return v
+
+
+def make_bool_unique_object(b: bool) -> Any:
+ class _CruBoolUnique:
+ _i = False
+
+ def __init__(self):
+ super().__init__(b)
+ if self._i:
+ raise ValueError("_CruAttrNotSet is a singleton!")
+ self._i = True
+
+ def __copy__(self):
+ return self
+
+ def __eq__(self, other):
+ return isinstance(other, _CruBoolUnique) or b == other
+
+ def __bool__(self):
+ return b
+
+ v = _CruBoolUnique()
+
+ return v
+
+
+CRU_NOT_FOUND = make_bool_unique_object(False)
+CRU_USE_DEFAULT = make_unique_object()
+CRU_DONT_CHANGE = make_unique_object()
+CRU_PLACEHOLDER = make_unique_object()