Skip to content

Commit f9c142b

Browse files
committed
Move custom type definitions to dedicated file
1 parent b2f052e commit f9c142b

3 files changed

Lines changed: 42 additions & 40 deletions

File tree

dpath/segments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from dpath import options
66
from dpath.exceptions import InvalidGlob, InvalidKeyName, PathNotFound
7-
from dpath.util import PathSegment, Creator, Hints
7+
from dpath.types import PathSegment, Creator, Hints
88

99

1010
def make_walkable(node) -> Iterator[Tuple[PathSegment, Any]]:

dpath/types.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from enum import IntFlag, auto
2+
from typing import Union, Any, Callable, Sequence, Tuple, Dict, List, Optional
3+
4+
5+
class MergeType(IntFlag):
6+
ADDITIVE = auto()
7+
"""List objects are combined onto one long list (NOT a set). This is the default flag."""
8+
9+
REPLACE = auto()
10+
"""Instead of combining list objects, when 2 list objects are at an equal depth of merge, replace the destination
11+
with the source."""
12+
13+
TYPESAFE = auto()
14+
"""When 2 keys at equal levels are of different types, raise a TypeError exception. By default, the source
15+
replaces the destination in this situation."""
16+
17+
18+
PathSegment = Union[int, str]
19+
"""Type alias for dict path segments where integers are explicitly casted."""
20+
21+
Filter = Callable[[Any], bool]
22+
"""Type alias for filter functions.
23+
24+
(Any) -> bool"""
25+
26+
Hints = Sequence[Tuple[PathSegment, type]]
27+
"""Type alias for creator function hint sequences."""
28+
29+
Creator = Callable[[Union[Dict, List], Sequence[PathSegment], int, Optional[Hints]], None]
30+
"""Type alias for creator functions.
31+
32+
Example creator function signature:
33+
34+
def creator(
35+
current: Union[Dict, List],
36+
segments: Sequence[PathSegment],
37+
i: int,
38+
hints: Sequence[Tuple[PathSegment, type]] = ()
39+
)"""

dpath/util.py

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,13 @@
11
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
43

54
from dpath import options, segments
65
from dpath.exceptions import InvalidKeyName, PathNotFound
6+
from dpath.types import PathSegment, Filter, Creator, MergeType
77

88
_DEFAULT_SENTINEL = object()
99

1010

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-
4811
def _split_path(path: str, separator: str) -> Union[List[PathSegment], PathSegment]:
4912
"""
5013
Given a path and separator, return a tuple of segments. If path is

0 commit comments

Comments
 (0)