Skip to content

Commit 74b4b7e

Browse files
authored
Improve None type hints
1 parent a13283b commit 74b4b7e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

dpath/__init__.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Needed for pre-3.10 versions
2+
from __future__ import annotations
3+
14
__all__ = [
25
"new",
36
"delete",
@@ -48,7 +51,7 @@ def _split_path(path: Path, separator: Optional[str] = "/") -> Union[List[PathSe
4851
return split_segments
4952

5053

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:
5255
"""
5356
Set the element at the terminus of path to value, and create
5457
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
6871
return segments.set(obj, split_segments, value)
6972

7073

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:
7275
"""
7376
Given a obj, delete all elements that match the glob.
7477
@@ -127,7 +130,7 @@ def f(obj, pair, counter):
127130
return deleted
128131

129132

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:
131134
"""
132135
Given a path glob, set all existing elements in the document
133136
to the given value. Returns the number of elements changed.
@@ -193,7 +196,7 @@ def f(_, pair, results):
193196
return results[0]
194197

195198

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):
197200
"""
198201
Given an object and a path glob, return an array of all values which match
199202
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
203206
return [v for p, v in search(obj, glob, yielded, separator, afilter, dirs)]
204207

205208

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):
207210
"""
208211
Given a path glob, return a dictionary containing all keys
209212
that matched the given glob.
210213
211214
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
213216
every element in the document that matched the glob.
214217
"""
215218

@@ -218,7 +221,7 @@ def search(obj: MutableMapping, glob: Glob, yielded=False, separator="/", afilte
218221
def keeper(path, found):
219222
"""
220223
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.
222225
"""
223226
if not dirs and not segments.leaf(found):
224227
return False
@@ -245,7 +248,13 @@ def f(obj, pair, result):
245248
return segments.fold(obj, f, {})
246249

247250

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+
):
249258
"""
250259
Merge source into destination. Like dict.update() but performs deep
251260
merging.

0 commit comments

Comments
 (0)