1111 "segments" ,
1212 "types" ,
1313 "version" ,
14+ "MergeType" ,
15+ "PathSegment" ,
16+ "Filter" ,
17+ "Glob" ,
18+ "Path" ,
19+ "Hints" ,
20+ "Creator" ,
1421]
1522
1623from collections .abc import MutableMapping , MutableSequence
17- from typing import Union , List , Dict , Any
24+ from typing import Union , List , Any , Callable , Optional
1825
1926from dpath import segments , options
2027from dpath .exceptions import InvalidKeyName , PathNotFound
21- from dpath .types import MergeType , PathSegment , Creator , Filter
28+ from dpath .types import MergeType , PathSegment , Creator , Filter , Glob , Path , Hints
2229
2330_DEFAULT_SENTINEL = object ()
2431
2532
26- def _split_path (path : str , separator : str ) -> Union [List [PathSegment ], PathSegment ]:
33+ def _split_path (path : Path , separator : Optional [ str ] ) -> Union [List [PathSegment ], PathSegment ]:
2734 """
2835 Given a path and separator, return a tuple of segments. If path is
2936 already a non-leaf thing, return it.
@@ -51,7 +58,7 @@ def _split_path(path: str, separator: str) -> Union[List[PathSegment], PathSegme
5158 return split_segments
5259
5360
54- def new (obj : Dict , path : str , value , separator = "/" , creator : Creator = None ) -> Dict :
61+ def new (obj : MutableMapping , path : Path , value , separator = "/" , creator : Creator = None ) -> MutableMapping :
5562 """
5663 Set the element at the terminus of path to value, and create
5764 it if it does not exist (as opposed to 'set' that can only
@@ -71,7 +78,7 @@ def new(obj: Dict, path: str, value, separator="/", creator: Creator = None) ->
7178 return segments .set (obj , split_segments , value )
7279
7380
74- def delete (obj : Dict , glob : str , separator = "/" , afilter : Filter = None ) -> int :
81+ def delete (obj : MutableMapping , glob : Glob , separator = "/" , afilter : Filter = None ) -> int :
7582 """
7683 Given a obj, delete all elements that match the glob.
7784
@@ -130,7 +137,7 @@ def f(obj, pair, counter):
130137 return deleted
131138
132139
133- def set (obj : Dict , glob : str , value , separator = "/" , afilter : Filter = None ) -> int :
140+ def set (obj : MutableMapping , glob : Glob , value , separator = "/" , afilter : Filter = None ) -> int :
134141 """
135142 Given a path glob, set all existing elements in the document
136143 to the given value. Returns the number of elements changed.
@@ -155,7 +162,12 @@ def f(obj, pair, counter):
155162 return changed
156163
157164
158- def get (obj : Dict , glob : str , separator = "/" , default : Any = _DEFAULT_SENTINEL ) -> Dict :
165+ def get (
166+ obj : MutableMapping ,
167+ glob : Glob ,
168+ separator = "/" ,
169+ default : Any = _DEFAULT_SENTINEL
170+ ) -> Union [MutableMapping , object , Callable ]:
159171 """
160172 Given an object which contains only one possible match for the given glob,
161173 return the value for the leaf matching the given glob.
@@ -191,7 +203,7 @@ def f(_, pair, results):
191203 return results [0 ]
192204
193205
194- def values (obj : Dict , glob : str , separator = "/" , afilter : Filter = None , dirs = True ):
206+ def values (obj : MutableMapping , glob : Glob , separator = "/" , afilter : Filter = None , dirs = True ):
195207 """
196208 Given an object and a path glob, return an array of all values which match
197209 the glob. The arguments to this function are identical to those of search().
@@ -201,7 +213,7 @@ def values(obj: Dict, glob: str, separator="/", afilter: Filter = None, dirs=Tru
201213 return [v for p , v in search (obj , glob , yielded , separator , afilter , dirs )]
202214
203215
204- def search (obj : Dict , glob : str , yielded = False , separator = "/" , afilter : Filter = None , dirs = True ):
216+ def search (obj : MutableMapping , glob : Glob , yielded = False , separator = "/" , afilter : Filter = None , dirs = True ):
205217 """
206218 Given a path glob, return a dictionary containing all keys
207219 that matched the given glob.
@@ -243,7 +255,7 @@ def f(obj, pair, result):
243255 return segments .fold (obj , f , {})
244256
245257
246- def merge (dst : Dict , src : Dict , separator = "/" , afilter : Filter = None , flags = MergeType .ADDITIVE ):
258+ def merge (dst : MutableMapping , src : MutableMapping , separator = "/" , afilter : Filter = None , flags = MergeType .ADDITIVE ):
247259 """
248260 Merge source into destination. Like dict.update() but performs deep
249261 merging.
0 commit comments