-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtypes.py
More file actions
42 lines (33 loc) · 911 Bytes
/
types.py
File metadata and controls
42 lines (33 loc) · 911 Bytes
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
from __future__ import annotations
from typing import Any, Dict, Literal, Union, get_args
from typing_extensions import TypeGuard, TypeVar
MetadataT = TypeVar("MetadataT", default=Dict[str, object])
ConditionOperator = Literal[
"EQUAL",
"GREATER_THAN",
"LESS_THAN",
"LESS_THAN_INCLUSIVE",
"CONTAINS",
"GREATER_THAN_INCLUSIVE",
"NOT_CONTAINS",
"NOT_EQUAL",
"REGEX",
"PERCENTAGE_SPLIT",
"MODULO",
"IS_SET",
"IS_NOT_SET",
"IN",
]
RuleType = Literal[
"ALL",
"ANY",
"NONE",
]
ContextValue = Union[None, int, float, bool, str]
_context_value_types = get_args(ContextValue)
def is_context_value(value: Any) -> TypeGuard[ContextValue]:
"""
Check if the value is a valid context value type.
This function is used to determine if a value can be treated as a context value.
"""
return isinstance(value, _context_value_types)