dotted-notation 0.43.16__tar.gz → 0.44.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/CHANGELOG.md +34 -0
- {dotted_notation-0.43.16/dotted_notation.egg-info → dotted_notation-0.44.0}/PKG-INFO +57 -15
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/README.md +56 -14
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/__init__.py +14 -14
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/api.py +174 -168
- {dotted_notation-0.43.16 → dotted_notation-0.44.0/dotted_notation.egg-info}/PKG-INFO +57 -15
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/pyproject.toml +1 -1
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/LICENSE +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/MANIFEST.in +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/__main__.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/access.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/base.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/cli/__init__.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/cli/_compat.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/cli/formats.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/cli/main.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/containers.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/engine.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/filters.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/grammar.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/groups.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/matchers.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/predicates.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/recursive.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/results.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/sql/__init__.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/sql/core.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/sql/pg.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/transforms.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/utils.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/utypes.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted/wrappers.py +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted_notation.egg-info/SOURCES.txt +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted_notation.egg-info/dependency_links.txt +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted_notation.egg-info/entry_points.txt +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted_notation.egg-info/requires.txt +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/dotted_notation.egg-info/top_level.txt +0 -0
- {dotted_notation-0.43.16 → dotted_notation-0.44.0}/setup.cfg +0 -0
|
@@ -3,6 +3,40 @@
|
|
|
3
3
|
All notable changes to `dotted` are recorded here. Versions prior to
|
|
4
4
|
the ones listed are omitted — browse git history for earlier entries.
|
|
5
5
|
|
|
6
|
+
## [0.44.0]
|
|
7
|
+
|
|
8
|
+
### Changed (breaking)
|
|
9
|
+
- Public-API parameter renamed from `key` to `path` across `get`,
|
|
10
|
+
`update`, `update_if`, `remove`, `remove_if`, `has`, `setdefault`,
|
|
11
|
+
`build`, `mutable`, `match`, `parse`, and all `is_*` predicates.
|
|
12
|
+
Positional calls are unaffected; keyword callers must update
|
|
13
|
+
(e.g. `update(obj, key=...)` → `update(obj, path=...)`).
|
|
14
|
+
- `build_multi(obj, keys=...)` → `build_multi(obj, paths=...)`.
|
|
15
|
+
- `setdefault_multi`, `update_multi`, `pack` rename `keyvalues=` to
|
|
16
|
+
`pathvalues=`.
|
|
17
|
+
- `remove_multi` / `remove_if_multi` rename `keys_only=` to
|
|
18
|
+
`paths_only=`.
|
|
19
|
+
- `assemble` / `assemble_multi` rename `keys`/`keys_list` to
|
|
20
|
+
`segments`/`segments_list`.
|
|
21
|
+
- `remove_if` default pred signature: `lambda key: key is not None` →
|
|
22
|
+
`lambda path: path is not None`.
|
|
23
|
+
- `expand_multi`, `pluck_multi`, `assemble_multi` now return a **generator**
|
|
24
|
+
instead of a tuple, aligning with `get_multi`, `match_multi`, `walk_multi`,
|
|
25
|
+
`translate_multi`, `setdefault_multi`. Callers that consumed the return as a
|
|
26
|
+
tuple (indexing, `len()`, equality) must wrap with `tuple(...)` /
|
|
27
|
+
`list(...)`. Singular forms (`expand`, `pluck`, `assemble`) unchanged.
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
- `is_mutable` — preferred alias for `mutable`, parallels
|
|
31
|
+
`is_pattern`, `is_template`, etc. `mutable` remains as an alias.
|
|
32
|
+
|
|
33
|
+
### Rationale
|
|
34
|
+
- The library distinguishes a *path* (the whole dotted expression)
|
|
35
|
+
from a *path segment* or *field* (one component), with *key field*
|
|
36
|
+
referring specifically to the dot-notation kind (vs bracket or
|
|
37
|
+
attr fields). Using bare `key` as a parameter name for the whole
|
|
38
|
+
path conflated those. Docs and API now use precise terminology.
|
|
39
|
+
|
|
6
40
|
## [0.43.16]
|
|
7
41
|
|
|
8
42
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dotted_notation
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.44.0
|
|
4
4
|
Summary: Dotted notation for safe nested data traversal with optional chaining, pattern matching, and transforms
|
|
5
5
|
Author-email: Frey Waid <logophage1@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -247,6 +247,39 @@ Several Python libraries handle nested data access. Here's how dotted compares:
|
|
|
247
247
|
<a id="breaking-changes"></a>
|
|
248
248
|
## Breaking Changes
|
|
249
249
|
|
|
250
|
+
### v0.44.0
|
|
251
|
+
- **Parameter renamed from `key` to `path`** across the public API to align with
|
|
252
|
+
the terminology used throughout the docs (a _path_ is the whole dotted
|
|
253
|
+
expression; a _path segment_ or _field_ is one component). Positional calls
|
|
254
|
+
are unaffected; keyword callers must update:
|
|
255
|
+
- `get(obj, key=...)` → `get(obj, path=...)`
|
|
256
|
+
- `update(obj, key=...)`, `update_if(obj, key=...)` → `update(obj, path=...)`, etc.
|
|
257
|
+
- `remove(obj, key=...)`, `remove_if(obj, key=...)` → `remove(obj, path=...)`, etc.
|
|
258
|
+
- `has`, `setdefault`, `build`, `mutable`, `match` — same rename
|
|
259
|
+
- `is_pattern(key=...)`, `is_template(key=...)`, `is_reference(key=...)`,
|
|
260
|
+
`is_indeterminate(key=...)`, `is_simple(key=...)`, `is_inverted(key=...)` —
|
|
261
|
+
all take `path=` now.
|
|
262
|
+
- `parse(key=...)` → `parse(path=...)`
|
|
263
|
+
- `build_multi(obj, keys=...)` → `build_multi(obj, paths=...)`
|
|
264
|
+
- `setdefault_multi(obj, keyvalues=...)`, `update_multi(obj, keyvalues=...)` →
|
|
265
|
+
`setdefault_multi(obj, pathvalues=...)`, `update_multi(obj, pathvalues=...)`
|
|
266
|
+
- `pack(keyvalues=...)` → `pack(pathvalues=...)`
|
|
267
|
+
- `remove_multi(..., keys_only=...)`, `remove_if_multi(..., keys_only=...)` →
|
|
268
|
+
`remove_multi(..., paths_only=...)`, `remove_if_multi(..., paths_only=...)`
|
|
269
|
+
- `assemble(keys)` / `assemble_multi(keys_list)` → `assemble(segments)` /
|
|
270
|
+
`assemble_multi(segments_list)`
|
|
271
|
+
- `remove_if` default pred signature: `lambda key: key is not None` →
|
|
272
|
+
`lambda path: path is not None`
|
|
273
|
+
- **`is_mutable` added as the preferred name for `mutable`** — parallels the
|
|
274
|
+
other `is_*` predicates. `mutable` remains as an alias.
|
|
275
|
+
- **`expand_multi`, `pluck_multi`, `assemble_multi` now return a generator**
|
|
276
|
+
instead of a tuple, aligning with the other read-side `_multi` APIs
|
|
277
|
+
(`get_multi`, `match_multi`, `walk_multi`, `translate_multi`,
|
|
278
|
+
`setdefault_multi`). Callers that consumed the return as a tuple (indexing
|
|
279
|
+
`r[0]`, `len(r)`, equality `r == (...)`) must now materialize:
|
|
280
|
+
`tuple(pluck_multi(...))`. The singular forms (`expand`, `pluck`, `assemble`)
|
|
281
|
+
are unchanged.
|
|
282
|
+
|
|
250
283
|
### v0.43.4
|
|
251
284
|
- **`is_pattern` no longer returns `True` for substitutions**. `Subst` previously
|
|
252
285
|
inherited from `Pattern` in the class hierarchy, so any path containing a
|
|
@@ -327,7 +360,7 @@ Parsed dotted paths are LRU-cached (after the first parse of a given path string
|
|
|
327
360
|
<a id="get"></a>
|
|
328
361
|
### Get
|
|
329
362
|
|
|
330
|
-
See the Paths, Patterns, and Operators sections below for the full notation.
|
|
363
|
+
Get the value at a dotted path. See the Paths, Patterns, and Operators sections below for the full notation.
|
|
331
364
|
|
|
332
365
|
>>> import dotted
|
|
333
366
|
>>> dotted.get({'a': {'b': {'c': {'d': 'nested'}}}}, 'a.b.c.d')
|
|
@@ -336,8 +369,8 @@ See the Paths, Patterns, and Operators sections below for the full notation.
|
|
|
336
369
|
<a id="update"></a>
|
|
337
370
|
### Update
|
|
338
371
|
|
|
339
|
-
Update
|
|
340
|
-
|
|
372
|
+
Update mutates the object when possible and always returns the result. For immutable
|
|
373
|
+
objects, use the return value.
|
|
341
374
|
|
|
342
375
|
>>> import dotted
|
|
343
376
|
>>> l = []
|
|
@@ -448,8 +481,8 @@ Use `remove_if_multi` for batch removal with per-item `(key, val, pred)`.
|
|
|
448
481
|
<a id="match"></a>
|
|
449
482
|
### Match
|
|
450
483
|
|
|
451
|
-
|
|
452
|
-
can match via wildcard OR via regex.
|
|
484
|
+
Match a dotted-style pattern to a path. Partial matching is on by default. You
|
|
485
|
+
can match via wildcard OR via regex. Here's a regex example:
|
|
453
486
|
|
|
454
487
|
>>> import dotted
|
|
455
488
|
>>> dotted.match('/a.+/', 'abced.b')
|
|
@@ -553,7 +586,7 @@ Returns `None` if no pattern matches:
|
|
|
553
586
|
<a id="expand"></a>
|
|
554
587
|
### Expand
|
|
555
588
|
|
|
556
|
-
|
|
589
|
+
Expand a pattern into all matching paths in an object.
|
|
557
590
|
|
|
558
591
|
>>> import dotted
|
|
559
592
|
>>> d = {'hello': {'there': [1, 2, 3]}, 'bye': 7}
|
|
@@ -586,7 +619,7 @@ decide which later-branch results to suppress.
|
|
|
586
619
|
<a id="has"></a>
|
|
587
620
|
### Has
|
|
588
621
|
|
|
589
|
-
Check if a
|
|
622
|
+
Check if a path or pattern exists in an object.
|
|
590
623
|
|
|
591
624
|
>>> import dotted
|
|
592
625
|
>>> d = {'a': {'b': 1}}
|
|
@@ -625,13 +658,13 @@ This is useful when you need to know whether to use the return value:
|
|
|
625
658
|
<a id="setdefault"></a>
|
|
626
659
|
### Setdefault
|
|
627
660
|
|
|
628
|
-
Set a value only if the
|
|
661
|
+
Set a value only if the path doesn't already exist. Creates nested structures as needed.
|
|
629
662
|
|
|
630
663
|
>>> import dotted
|
|
631
664
|
>>> d = {'a': 1}
|
|
632
|
-
>>> dotted.setdefault(d, 'a', 999) #
|
|
665
|
+
>>> dotted.setdefault(d, 'a', 999) # path exists, no change; returns value
|
|
633
666
|
1
|
|
634
|
-
>>> dotted.setdefault(d, 'b', 2) #
|
|
667
|
+
>>> dotted.setdefault(d, 'b', 2) # path missing, sets value; returns it
|
|
635
668
|
2
|
|
636
669
|
>>> dotted.setdefault({}, 'a.b.c', 7) # creates nested structure; returns value
|
|
637
670
|
7
|
|
@@ -639,7 +672,7 @@ Set a value only if the key doesn't already exist. Creates nested structures as
|
|
|
639
672
|
<a id="pluck"></a>
|
|
640
673
|
### Pluck
|
|
641
674
|
|
|
642
|
-
Extract (
|
|
675
|
+
Extract (path, value) pairs from an object matching a pattern.
|
|
643
676
|
|
|
644
677
|
>>> import dotted
|
|
645
678
|
>>> d = {'a': 1, 'b': 2, 'nested': {'x': 10}}
|
|
@@ -685,6 +718,8 @@ which attributes are included:
|
|
|
685
718
|
- `Attrs.standard` — non-dunder attributes
|
|
686
719
|
- `Attrs.special` — dunder attributes (`__name__`, etc.)
|
|
687
720
|
|
|
721
|
+
For example:
|
|
722
|
+
|
|
688
723
|
>>> class Pt:
|
|
689
724
|
... def __init__(self, x, y):
|
|
690
725
|
... self.x = x
|
|
@@ -697,7 +732,7 @@ Pass both to include all attributes: `attrs=[Attrs.standard, Attrs.special]`.
|
|
|
697
732
|
<a id="pack"></a>
|
|
698
733
|
### Pack
|
|
699
734
|
|
|
700
|
-
Build a new object from
|
|
735
|
+
Build a new object from path-value pairs. The inverse of `unpack` — infers the root
|
|
701
736
|
container type automatically.
|
|
702
737
|
|
|
703
738
|
>>> import dotted
|
|
@@ -744,7 +779,7 @@ All three accept `attrs=` (same as `unpack`):
|
|
|
744
779
|
<a id="build"></a>
|
|
745
780
|
### Build
|
|
746
781
|
|
|
747
|
-
Create a default nested structure for a dotted
|
|
782
|
+
Create a default nested structure for a dotted path.
|
|
748
783
|
|
|
749
784
|
>>> import dotted
|
|
750
785
|
>>> dotted.build({}, 'a.b.c')
|
|
@@ -825,7 +860,14 @@ produce `[]`.
|
|
|
825
860
|
|
|
826
861
|
Most operations have `*_multi` variants for batch processing:
|
|
827
862
|
|
|
828
|
-
**Note:** `
|
|
863
|
+
**Note:** The read-side `_multi` APIs — `get_multi`, `match_multi`, `expand_multi`,
|
|
864
|
+
`pluck_multi`, `walk_multi`, `translate_multi`, `assemble_multi`, and
|
|
865
|
+
`setdefault_multi` — return a **generator**, not a list or tuple. Consume with
|
|
866
|
+
`list()` / `tuple()` / `for`. The write-side `_multi` APIs (`update_multi`,
|
|
867
|
+
`remove_multi`, `build_multi`, `apply_multi`, etc.) return the mutated object.
|
|
868
|
+
The generator shape keeps input and output in the same style when you pass an
|
|
869
|
+
iterator or generator of paths — lazy in, lazy out — and lets callers early-exit
|
|
870
|
+
before a full traversal completes.
|
|
829
871
|
|
|
830
872
|
>>> import dotted
|
|
831
873
|
>>> d = {'a': 1, 'b': 2, 'c': 3}
|
|
@@ -207,6 +207,39 @@ Several Python libraries handle nested data access. Here's how dotted compares:
|
|
|
207
207
|
<a id="breaking-changes"></a>
|
|
208
208
|
## Breaking Changes
|
|
209
209
|
|
|
210
|
+
### v0.44.0
|
|
211
|
+
- **Parameter renamed from `key` to `path`** across the public API to align with
|
|
212
|
+
the terminology used throughout the docs (a _path_ is the whole dotted
|
|
213
|
+
expression; a _path segment_ or _field_ is one component). Positional calls
|
|
214
|
+
are unaffected; keyword callers must update:
|
|
215
|
+
- `get(obj, key=...)` → `get(obj, path=...)`
|
|
216
|
+
- `update(obj, key=...)`, `update_if(obj, key=...)` → `update(obj, path=...)`, etc.
|
|
217
|
+
- `remove(obj, key=...)`, `remove_if(obj, key=...)` → `remove(obj, path=...)`, etc.
|
|
218
|
+
- `has`, `setdefault`, `build`, `mutable`, `match` — same rename
|
|
219
|
+
- `is_pattern(key=...)`, `is_template(key=...)`, `is_reference(key=...)`,
|
|
220
|
+
`is_indeterminate(key=...)`, `is_simple(key=...)`, `is_inverted(key=...)` —
|
|
221
|
+
all take `path=` now.
|
|
222
|
+
- `parse(key=...)` → `parse(path=...)`
|
|
223
|
+
- `build_multi(obj, keys=...)` → `build_multi(obj, paths=...)`
|
|
224
|
+
- `setdefault_multi(obj, keyvalues=...)`, `update_multi(obj, keyvalues=...)` →
|
|
225
|
+
`setdefault_multi(obj, pathvalues=...)`, `update_multi(obj, pathvalues=...)`
|
|
226
|
+
- `pack(keyvalues=...)` → `pack(pathvalues=...)`
|
|
227
|
+
- `remove_multi(..., keys_only=...)`, `remove_if_multi(..., keys_only=...)` →
|
|
228
|
+
`remove_multi(..., paths_only=...)`, `remove_if_multi(..., paths_only=...)`
|
|
229
|
+
- `assemble(keys)` / `assemble_multi(keys_list)` → `assemble(segments)` /
|
|
230
|
+
`assemble_multi(segments_list)`
|
|
231
|
+
- `remove_if` default pred signature: `lambda key: key is not None` →
|
|
232
|
+
`lambda path: path is not None`
|
|
233
|
+
- **`is_mutable` added as the preferred name for `mutable`** — parallels the
|
|
234
|
+
other `is_*` predicates. `mutable` remains as an alias.
|
|
235
|
+
- **`expand_multi`, `pluck_multi`, `assemble_multi` now return a generator**
|
|
236
|
+
instead of a tuple, aligning with the other read-side `_multi` APIs
|
|
237
|
+
(`get_multi`, `match_multi`, `walk_multi`, `translate_multi`,
|
|
238
|
+
`setdefault_multi`). Callers that consumed the return as a tuple (indexing
|
|
239
|
+
`r[0]`, `len(r)`, equality `r == (...)`) must now materialize:
|
|
240
|
+
`tuple(pluck_multi(...))`. The singular forms (`expand`, `pluck`, `assemble`)
|
|
241
|
+
are unchanged.
|
|
242
|
+
|
|
210
243
|
### v0.43.4
|
|
211
244
|
- **`is_pattern` no longer returns `True` for substitutions**. `Subst` previously
|
|
212
245
|
inherited from `Pattern` in the class hierarchy, so any path containing a
|
|
@@ -287,7 +320,7 @@ Parsed dotted paths are LRU-cached (after the first parse of a given path string
|
|
|
287
320
|
<a id="get"></a>
|
|
288
321
|
### Get
|
|
289
322
|
|
|
290
|
-
See the Paths, Patterns, and Operators sections below for the full notation.
|
|
323
|
+
Get the value at a dotted path. See the Paths, Patterns, and Operators sections below for the full notation.
|
|
291
324
|
|
|
292
325
|
>>> import dotted
|
|
293
326
|
>>> dotted.get({'a': {'b': {'c': {'d': 'nested'}}}}, 'a.b.c.d')
|
|
@@ -296,8 +329,8 @@ See the Paths, Patterns, and Operators sections below for the full notation.
|
|
|
296
329
|
<a id="update"></a>
|
|
297
330
|
### Update
|
|
298
331
|
|
|
299
|
-
Update
|
|
300
|
-
|
|
332
|
+
Update mutates the object when possible and always returns the result. For immutable
|
|
333
|
+
objects, use the return value.
|
|
301
334
|
|
|
302
335
|
>>> import dotted
|
|
303
336
|
>>> l = []
|
|
@@ -408,8 +441,8 @@ Use `remove_if_multi` for batch removal with per-item `(key, val, pred)`.
|
|
|
408
441
|
<a id="match"></a>
|
|
409
442
|
### Match
|
|
410
443
|
|
|
411
|
-
|
|
412
|
-
can match via wildcard OR via regex.
|
|
444
|
+
Match a dotted-style pattern to a path. Partial matching is on by default. You
|
|
445
|
+
can match via wildcard OR via regex. Here's a regex example:
|
|
413
446
|
|
|
414
447
|
>>> import dotted
|
|
415
448
|
>>> dotted.match('/a.+/', 'abced.b')
|
|
@@ -513,7 +546,7 @@ Returns `None` if no pattern matches:
|
|
|
513
546
|
<a id="expand"></a>
|
|
514
547
|
### Expand
|
|
515
548
|
|
|
516
|
-
|
|
549
|
+
Expand a pattern into all matching paths in an object.
|
|
517
550
|
|
|
518
551
|
>>> import dotted
|
|
519
552
|
>>> d = {'hello': {'there': [1, 2, 3]}, 'bye': 7}
|
|
@@ -546,7 +579,7 @@ decide which later-branch results to suppress.
|
|
|
546
579
|
<a id="has"></a>
|
|
547
580
|
### Has
|
|
548
581
|
|
|
549
|
-
Check if a
|
|
582
|
+
Check if a path or pattern exists in an object.
|
|
550
583
|
|
|
551
584
|
>>> import dotted
|
|
552
585
|
>>> d = {'a': {'b': 1}}
|
|
@@ -585,13 +618,13 @@ This is useful when you need to know whether to use the return value:
|
|
|
585
618
|
<a id="setdefault"></a>
|
|
586
619
|
### Setdefault
|
|
587
620
|
|
|
588
|
-
Set a value only if the
|
|
621
|
+
Set a value only if the path doesn't already exist. Creates nested structures as needed.
|
|
589
622
|
|
|
590
623
|
>>> import dotted
|
|
591
624
|
>>> d = {'a': 1}
|
|
592
|
-
>>> dotted.setdefault(d, 'a', 999) #
|
|
625
|
+
>>> dotted.setdefault(d, 'a', 999) # path exists, no change; returns value
|
|
593
626
|
1
|
|
594
|
-
>>> dotted.setdefault(d, 'b', 2) #
|
|
627
|
+
>>> dotted.setdefault(d, 'b', 2) # path missing, sets value; returns it
|
|
595
628
|
2
|
|
596
629
|
>>> dotted.setdefault({}, 'a.b.c', 7) # creates nested structure; returns value
|
|
597
630
|
7
|
|
@@ -599,7 +632,7 @@ Set a value only if the key doesn't already exist. Creates nested structures as
|
|
|
599
632
|
<a id="pluck"></a>
|
|
600
633
|
### Pluck
|
|
601
634
|
|
|
602
|
-
Extract (
|
|
635
|
+
Extract (path, value) pairs from an object matching a pattern.
|
|
603
636
|
|
|
604
637
|
>>> import dotted
|
|
605
638
|
>>> d = {'a': 1, 'b': 2, 'nested': {'x': 10}}
|
|
@@ -645,6 +678,8 @@ which attributes are included:
|
|
|
645
678
|
- `Attrs.standard` — non-dunder attributes
|
|
646
679
|
- `Attrs.special` — dunder attributes (`__name__`, etc.)
|
|
647
680
|
|
|
681
|
+
For example:
|
|
682
|
+
|
|
648
683
|
>>> class Pt:
|
|
649
684
|
... def __init__(self, x, y):
|
|
650
685
|
... self.x = x
|
|
@@ -657,7 +692,7 @@ Pass both to include all attributes: `attrs=[Attrs.standard, Attrs.special]`.
|
|
|
657
692
|
<a id="pack"></a>
|
|
658
693
|
### Pack
|
|
659
694
|
|
|
660
|
-
Build a new object from
|
|
695
|
+
Build a new object from path-value pairs. The inverse of `unpack` — infers the root
|
|
661
696
|
container type automatically.
|
|
662
697
|
|
|
663
698
|
>>> import dotted
|
|
@@ -704,7 +739,7 @@ All three accept `attrs=` (same as `unpack`):
|
|
|
704
739
|
<a id="build"></a>
|
|
705
740
|
### Build
|
|
706
741
|
|
|
707
|
-
Create a default nested structure for a dotted
|
|
742
|
+
Create a default nested structure for a dotted path.
|
|
708
743
|
|
|
709
744
|
>>> import dotted
|
|
710
745
|
>>> dotted.build({}, 'a.b.c')
|
|
@@ -785,7 +820,14 @@ produce `[]`.
|
|
|
785
820
|
|
|
786
821
|
Most operations have `*_multi` variants for batch processing:
|
|
787
822
|
|
|
788
|
-
**Note:** `
|
|
823
|
+
**Note:** The read-side `_multi` APIs — `get_multi`, `match_multi`, `expand_multi`,
|
|
824
|
+
`pluck_multi`, `walk_multi`, `translate_multi`, `assemble_multi`, and
|
|
825
|
+
`setdefault_multi` — return a **generator**, not a list or tuple. Consume with
|
|
826
|
+
`list()` / `tuple()` / `for`. The write-side `_multi` APIs (`update_multi`,
|
|
827
|
+
`remove_multi`, `build_multi`, `apply_multi`, etc.) return the mutated object.
|
|
828
|
+
The generator shape keeps input and output in the same style when you pass an
|
|
829
|
+
iterator or generator of paths — lazy in, lazy out — and lets callers early-exit
|
|
830
|
+
before a full traversal completes.
|
|
789
831
|
|
|
790
832
|
>>> import dotted
|
|
791
833
|
>>> d = {'a': 1, 'b': 2, 'c': 3}
|
|
@@ -12,24 +12,24 @@ Use dotted to fetch, update, and remove data from deeply nested structures.
|
|
|
12
12
|
|
|
13
13
|
Core Operations
|
|
14
14
|
---------------
|
|
15
|
-
get(obj,
|
|
16
|
-
update(obj,
|
|
17
|
-
remove(obj,
|
|
18
|
-
has(obj,
|
|
19
|
-
setdefault(obj,
|
|
20
|
-
|
|
15
|
+
get(obj, path) Get value at dotted path
|
|
16
|
+
update(obj, path, val) Update value at dotted path
|
|
17
|
+
remove(obj, path) Remove value at dotted path
|
|
18
|
+
has(obj, path) Check if path exists
|
|
19
|
+
setdefault(obj, p, v) Set value only if path missing
|
|
20
|
+
is_mutable(obj, path) Check if update would mutate in place
|
|
21
21
|
|
|
22
22
|
Pattern Matching
|
|
23
23
|
----------------
|
|
24
|
-
match(pattern,
|
|
24
|
+
match(pattern, path) Match pattern to path
|
|
25
25
|
replace(template, bind) Substitute $N in template path
|
|
26
|
-
expand(obj, pattern) Expand pattern to concrete
|
|
26
|
+
expand(obj, pattern) Expand pattern to concrete paths
|
|
27
27
|
|
|
28
28
|
Building & Plucking
|
|
29
29
|
-------------------
|
|
30
|
-
build(obj,
|
|
31
|
-
pack(
|
|
32
|
-
pluck(obj, pattern) Extract
|
|
30
|
+
build(obj, path) Build default structure for path
|
|
31
|
+
pack(pathvalues) Build object from path-value pairs
|
|
32
|
+
pluck(obj, pattern) Extract (path, value) pairs
|
|
33
33
|
walk(obj, pattern) Yield (path, value) pairs (lazy)
|
|
34
34
|
unpack(obj) Extract to dotted normal form
|
|
35
35
|
keys(obj) Dotted paths of obj
|
|
@@ -49,7 +49,7 @@ transform(name) Decorator for custom transforms
|
|
|
49
49
|
Constants
|
|
50
50
|
---------
|
|
51
51
|
ANY Match any value (for remove)
|
|
52
|
-
AUTO Auto-infer root container type ({} or []) from first
|
|
52
|
+
AUTO Auto-infer root container type ({} or []) from first path
|
|
53
53
|
|
|
54
54
|
For full documentation including all options and flags:
|
|
55
55
|
$ pydoc dotted.api
|
|
@@ -57,7 +57,7 @@ For full documentation including all options and flags:
|
|
|
57
57
|
"""
|
|
58
58
|
from .api import \
|
|
59
59
|
parse, is_pattern, is_template, is_reference, is_indeterminate, is_simple, \
|
|
60
|
-
is_inverted, mutable, quote, ANY, AUTO, Attrs, GroupMode, \
|
|
60
|
+
is_inverted, is_mutable, mutable, quote, ANY, AUTO, Attrs, GroupMode, \
|
|
61
61
|
register, transform, \
|
|
62
62
|
assemble, assemble_multi, \
|
|
63
63
|
build, build_multi, \
|
|
@@ -86,7 +86,7 @@ __all__ = [
|
|
|
86
86
|
'parse', 'assemble', 'assemble_multi', 'quote',
|
|
87
87
|
'is_pattern', 'is_template', 'is_reference',
|
|
88
88
|
'is_indeterminate', 'is_simple',
|
|
89
|
-
'is_inverted', 'mutable',
|
|
89
|
+
'is_inverted', 'is_mutable', 'mutable',
|
|
90
90
|
# SQL
|
|
91
91
|
'sqlize', 'Resolver', 'SQLFragment', 'ParamStyle', 'ParamPool', 'TranslationError',
|
|
92
92
|
# Constants
|