|
1 | 1 | from collections.abc import MutableMapping, MutableSequence |
2 | | -from enum import IntFlag, auto |
3 | | -from typing import Union, List, Any, Dict, Callable, Sequence, Tuple, Optional |
| 2 | +from typing import Union, List, Any, Dict |
4 | 3 |
|
5 | 4 | from dpath import options, segments |
6 | 5 | from dpath.exceptions import InvalidKeyName, PathNotFound |
| 6 | +from dpath.types import PathSegment, Filter, Creator, MergeType |
7 | 7 |
|
8 | 8 | _DEFAULT_SENTINEL = object() |
9 | 9 |
|
10 | 10 |
|
11 | | -class MergeType(IntFlag): |
12 | | - ADDITIVE = auto() |
13 | | - """List objects are combined onto one long list (NOT a set). This is the default flag.""" |
14 | | - |
15 | | - REPLACE = auto() |
16 | | - """Instead of combining list objects, when 2 list objects are at an equal depth of merge, replace the destination |
17 | | - with the source.""" |
18 | | - |
19 | | - TYPESAFE = auto() |
20 | | - """When 2 keys at equal levels are of different types, raise a TypeError exception. By default, the source |
21 | | - replaces the destination in this situation.""" |
22 | | - |
23 | | - |
24 | | -PathSegment = Union[int, str] |
25 | | -"""Type alias for dict path segments where integers are explicitly casted.""" |
26 | | - |
27 | | -Filter = Callable[[Any], bool] |
28 | | -"""Type alias for filter functions. |
29 | | -
|
30 | | -(Any) -> bool""" |
31 | | - |
32 | | -Hints = Sequence[Tuple[PathSegment, type]] |
33 | | -"""Type alias for creator function hint sequences.""" |
34 | | - |
35 | | -Creator = Callable[[Union[Dict, List], Sequence[PathSegment], int, Optional[Hints]], None] |
36 | | -"""Type alias for creator functions. |
37 | | -
|
38 | | -Example creator function signature: |
39 | | - |
40 | | - def creator( |
41 | | - current: Union[Dict, List], |
42 | | - segments: Sequence[PathSegment], |
43 | | - i: int, |
44 | | - hints: Sequence[Tuple[PathSegment, type]] = () |
45 | | - )""" |
46 | | - |
47 | | - |
48 | 11 | def _split_path(path: str, separator: str) -> Union[List[PathSegment], PathSegment]: |
49 | 12 | """ |
50 | 13 | Given a path and separator, return a tuple of segments. If path is |
|
0 commit comments