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 | 7fbc091ae8ed2a4bac215ee04d7c4b5d0218af4e (patch) | |
tree | ce5a6b3dc74a012766c6d09e7e97cf8eba25ff9e /tools/cru-py/cru/_const.py | |
parent | aaa855e3839130a79193f38969f07763f2773c5d (diff) | |
download | crupest-7fbc091ae8ed2a4bac215ee04d7c4b5d0218af4e.tar.gz crupest-7fbc091ae8ed2a4bac215ee04d7c4b5d0218af4e.tar.bz2 crupest-7fbc091ae8ed2a4bac215ee04d7c4b5d0218af4e.zip |
HALF WORK: 2024.11.28
Diffstat (limited to 'tools/cru-py/cru/_const.py')
-rw-r--r-- | tools/cru-py/cru/_const.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/cru-py/cru/_const.py b/tools/cru-py/cru/_const.py new file mode 100644 index 0000000..bc02c3a --- /dev/null +++ b/tools/cru-py/cru/_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, +) |