diff options
author | crupest <crupest@outlook.com> | 2024-11-11 01:12:29 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2024-12-18 18:31:27 +0800 |
commit | aaa855e3839130a79193f38969f07763f2773c5d (patch) | |
tree | e4cb238df4588f4633d9c1190136895865d51a98 /tools/cru-py/cru/_util/_const.py | |
parent | 95da3ade5bfa6ef39923cd3fc2a551ad983c1537 (diff) | |
download | crupest-aaa855e3839130a79193f38969f07763f2773c5d.tar.gz crupest-aaa855e3839130a79193f38969f07763f2773c5d.tar.bz2 crupest-aaa855e3839130a79193f38969f07763f2773c5d.zip |
HALF WORK: 2024.11.27
Diffstat (limited to 'tools/cru-py/cru/_util/_const.py')
-rw-r--r-- | tools/cru-py/cru/_util/_const.py | 49 |
1 files changed, 49 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..bc02c3a --- /dev/null +++ b/tools/cru-py/cru/_util/_const.py @@ -0,0 +1,49 @@ +from enum import Enum, auto +from typing import Self, TypeGuard, TypeVar + +from ._cru import CRU + +_T = TypeVar("_T") + + +class CruConstantBase(Enum): + @classmethod + def check(cls, v: _T | Self) -> TypeGuard[Self]: + return isinstance(v, cls) + + @classmethod + def check_not(cls, v: _T | Self) -> TypeGuard[_T]: + return not cls.check(v) + + @classmethod + def value(cls) -> Self: + return cls.VALUE # type: ignore + + +class CruNotFound(CruConstantBase): + VALUE = auto() + + +class CruUseDefault(CruConstantBase): + VALUE = auto() + + +class CruDontChange(CruConstantBase): + VALUE = auto() + + +class CruNoValue(CruConstantBase): + VALUE = auto() + + +class CruPlaceholder(CruConstantBase): + VALUE = auto() + + +CRU.add_objects( + CruNotFound, + CruUseDefault, + CruDontChange, + CruNoValue, + CruPlaceholder, +) |