1
+ # Needed for pre-3.10 versions
2
+ from __future__ import annotations
3
+
1
4
__all__ = [
2
5
"new" ,
3
6
"delete" ,
@@ -48,7 +51,7 @@ def _split_path(path: Path, separator: Optional[str] = "/") -> Union[List[PathSe
48
51
return split_segments
49
52
50
53
51
- def new (obj : MutableMapping , path : Path , value , separator = "/" , creator : Creator = None ) -> MutableMapping :
54
+ def new (obj : MutableMapping , path : Path , value , separator = "/" , creator : Creator | None = None ) -> MutableMapping :
52
55
"""
53
56
Set the element at the terminus of path to value, and create
54
57
it if it does not exist (as opposed to 'set' that can only
@@ -68,7 +71,7 @@ def new(obj: MutableMapping, path: Path, value, separator="/", creator: Creator
68
71
return segments .set (obj , split_segments , value )
69
72
70
73
71
- def delete (obj : MutableMapping , glob : Glob , separator = "/" , afilter : Filter = None ) -> int :
74
+ def delete (obj : MutableMapping , glob : Glob , separator = "/" , afilter : Filter | None = None ) -> int :
72
75
"""
73
76
Given a obj, delete all elements that match the glob.
74
77
@@ -127,7 +130,7 @@ def f(obj, pair, counter):
127
130
return deleted
128
131
129
132
130
- def set (obj : MutableMapping , glob : Glob , value , separator = "/" , afilter : Filter = None ) -> int :
133
+ def set (obj : MutableMapping , glob : Glob , value , separator = "/" , afilter : Filter | None = None ) -> int :
131
134
"""
132
135
Given a path glob, set all existing elements in the document
133
136
to the given value. Returns the number of elements changed.
@@ -193,7 +196,7 @@ def f(_, pair, results):
193
196
return results [0 ]
194
197
195
198
196
- def values (obj : MutableMapping , glob : Glob , separator = "/" , afilter : Filter = None , dirs = True ):
199
+ def values (obj : MutableMapping , glob : Glob , separator = "/" , afilter : Filter | None = None , dirs = True ):
197
200
"""
198
201
Given an object and a path glob, return an array of all values which match
199
202
the glob. The arguments to this function are identical to those of search().
@@ -203,13 +206,13 @@ def values(obj: MutableMapping, glob: Glob, separator="/", afilter: Filter = Non
203
206
return [v for p , v in search (obj , glob , yielded , separator , afilter , dirs )]
204
207
205
208
206
- def search (obj : MutableMapping , glob : Glob , yielded = False , separator = "/" , afilter : Filter = None , dirs = True ):
209
+ def search (obj : MutableMapping , glob : Glob , yielded = False , separator = "/" , afilter : Filter | None = None , dirs = True ):
207
210
"""
208
211
Given a path glob, return a dictionary containing all keys
209
212
that matched the given glob.
210
213
211
214
If 'yielded' is true, then a dictionary will not be returned.
212
- Instead tuples will be yielded in the form of (path, value) for
215
+ Instead, tuples will be yielded in the form of (path, value) for
213
216
every element in the document that matched the glob.
214
217
"""
215
218
@@ -218,7 +221,7 @@ def search(obj: MutableMapping, glob: Glob, yielded=False, separator="/", afilte
218
221
def keeper (path , found ):
219
222
"""
220
223
Generalized test for use in both yielded and folded cases.
221
- Returns True if we want this result. Otherwise returns False.
224
+ Returns True if we want this result. Otherwise, returns False.
222
225
"""
223
226
if not dirs and not segments .leaf (found ):
224
227
return False
@@ -245,7 +248,13 @@ def f(obj, pair, result):
245
248
return segments .fold (obj , f , {})
246
249
247
250
248
- def merge (dst : MutableMapping , src : MutableMapping , separator = "/" , afilter : Filter = None , flags = MergeType .ADDITIVE ):
251
+ def merge (
252
+ dst : MutableMapping ,
253
+ src : MutableMapping ,
254
+ separator = "/" ,
255
+ afilter : Filter | None = None ,
256
+ flags = MergeType .ADDITIVE
257
+ ):
249
258
"""
250
259
Merge source into destination. Like dict.update() but performs deep
251
260
merging.
0 commit comments