forked from canvas-medical/pydian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.py
51 lines (40 loc) · 1.33 KB
/
types.py
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
from enum import Enum
from typing import Any, Callable, TypeAlias
ApplyFunc: TypeAlias = Callable[[Any], Any]
ConditionalCheck: TypeAlias = Callable[[Any], bool]
MappingFunc: TypeAlias = Callable[..., dict[str, Any]]
class DROP(Enum):
"""
A DeleteRelativeObjectPlaceholder (abbrv. DROP) is a placeholder object that indicates
the object relative to the current value should be dropped. An "object" in this context
is a dict or a list.
Examples:
{ <-- Grandparent (rel to _value)
'A': { <-- Parent (rel to _value)
'B': { <-- This Object (rel to _value)
'C': _value
}
}
}
{ <-- Grandparent (rel to _value1 and _value2)
'A': [ <-- Parent (rel to _value1 and _value2)
{ <-- This Object (rel to _value1)
'B': _value1
},
{ <-- This Object (rel to _value2)
'B': _value2
}
]
}
"""
THIS_OBJECT = -1
PARENT = -2
GRANDPARENT = -3
GREATGRANDPARENT = -4
class KEEP:
"""
A value wrapped in a KEEP object should be ignored by the Mapper class when removing values.
Partial keeping is _not_ supported (i.e. a KEEP object within an object to be DROP-ed).
"""
def __init__(self, v: Any):
self.value = v