aboutsummaryrefslogtreecommitdiff
path: root/tools/cru-py/cru/util/_const.py
blob: 81409880c3c6a0b73aba688607b3fd1e1951b4f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from typing import Any

from ._cru import CRU


def cru_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 cru_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 = cru_make_bool_unique_object(False)
CRU_USE_DEFAULT = cru_make_unique_object()
CRU_DONT_CHANGE = cru_make_unique_object()
CRU_PLACEHOLDER = cru_make_unique_object()

CRU.add_objects(cru_make_unique_object, cru_make_bool_unique_object, CRU_NOT_FOUND, CRU_USE_DEFAULT,
                CRU_DONT_CHANGE, CRU_PLACEHOLDER)