dotted-notation 0.55.4__tar.gz → 0.55.5__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.
Files changed (51) hide show
  1. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/CHANGELOG.md +10 -0
  2. {dotted_notation-0.55.4/dotted_notation.egg-info → dotted_notation-0.55.5}/PKG-INFO +25 -2
  3. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/README.md +24 -1
  4. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/access.py +14 -0
  5. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/api.py +22 -8
  6. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/base.py +29 -7
  7. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/groups.py +29 -26
  8. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/recursive.py +26 -7
  9. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/wrappers.py +11 -5
  10. {dotted_notation-0.55.4 → dotted_notation-0.55.5/dotted_notation.egg-info}/PKG-INFO +25 -2
  11. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/pyproject.toml +1 -1
  12. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/LICENSE +0 -0
  13. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/MANIFEST.in +0 -0
  14. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/__init__.py +0 -0
  15. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/__main__.py +0 -0
  16. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/access.pxd +0 -0
  17. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/base.pxd +0 -0
  18. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/cli/__init__.py +0 -0
  19. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/cli/_compat.py +0 -0
  20. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/cli/formats.py +0 -0
  21. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/cli/main.py +0 -0
  22. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/containers.py +0 -0
  23. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/engine.pxd +0 -0
  24. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/engine.py +0 -0
  25. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/filters.pxd +0 -0
  26. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/filters.py +0 -0
  27. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/grammar.py +0 -0
  28. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/groups.pxd +0 -0
  29. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/matchers.pxd +0 -0
  30. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/matchers.py +0 -0
  31. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/native.py +0 -0
  32. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/predicates.py +0 -0
  33. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/recursive.pxd +0 -0
  34. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/results.py +0 -0
  35. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/transforms.py +0 -0
  36. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/translators/__init__.py +0 -0
  37. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/translators/core.py +0 -0
  38. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/translators/spark.py +0 -0
  39. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/translators/spark_pyspark.py +0 -0
  40. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/translators/sql.py +0 -0
  41. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/translators/sql_pg.py +0 -0
  42. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/utils.py +0 -0
  43. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/utypes.py +0 -0
  44. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted/wrappers.pxd +0 -0
  45. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted_notation.egg-info/SOURCES.txt +0 -0
  46. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted_notation.egg-info/dependency_links.txt +0 -0
  47. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted_notation.egg-info/entry_points.txt +0 -0
  48. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted_notation.egg-info/requires.txt +0 -0
  49. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/dotted_notation.egg-info/top_level.txt +0 -0
  50. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/setup.cfg +0 -0
  51. {dotted_notation-0.55.4 → dotted_notation-0.55.5}/setup.py +0 -0
@@ -3,6 +3,16 @@
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.55.5]
7
+
8
+ ### Fixed
9
+ - `match` and `match_multi` honor `strict=True`, which they took and
10
+ ignored: a key pattern matches only a key, a slot pattern only a
11
+ slot, an attr pattern only an attr, as strict mode does for `get`.
12
+ `match('[*]', 'table', strict=True)` and `match('*', '[0]',
13
+ strict=True)` are `None`. `**` reads keys, so under strict it
14
+ consumes only key segments; `*(.*,[*])` reads both.
15
+
6
16
  ## [0.55.4]
7
17
 
8
18
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dotted_notation
3
- Version: 0.55.4
3
+ Version: 0.55.5
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-Expression: MIT
@@ -705,6 +705,14 @@ depends on the data, so no part of the list covers it, and neither does
705
705
  >>> dotted.match('a[1:]', 'a[x=1]')
706
706
  >>> dotted.match('a[*]', 'a[x=1]')
707
707
 
708
+ A segment matches however it is read: `[*]` matches the key `table`, and `*` the slot
709
+ `[0]`. Pass `strict=True` to keep keys, slots and attrs apart, as
710
+ [strict mode](#strict-mode) does for `get`:
711
+
712
+ >>> dotted.match('[*]', 'table')
713
+ 'table'
714
+ >>> dotted.match('[*]', 'table', strict=True)
715
+
708
716
  <a id="replace"></a>
709
717
  ### Replace
710
718
 
@@ -1182,7 +1190,7 @@ Pass `strict=True` to enforce this separation:
1182
1190
  True
1183
1191
 
1184
1192
  Strict mode applies to all operations — `get`, `update`, `remove`, `has`, `expand`,
1185
- `pluck`, and their `_multi` variants. Mismatches silently return empty results, consistent
1193
+ `pluck`, `match`, and their `_multi` variants. Mismatches silently return empty results, consistent
1186
1194
  with dotted's safe traversal model:
1187
1195
 
1188
1196
  >>> dotted.has(d, '[0]', strict=True)
@@ -1197,6 +1205,21 @@ with dotted's safe traversal model:
1197
1205
  Use strict mode when your data mixes integer dict keys and list indices, and you need
1198
1206
  to distinguish between them.
1199
1207
 
1208
+ `match` and `match_multi` take `strict` too. By default a segment matches however it is
1209
+ read, so `[*]` matches a key and `*` a slot. Strict keeps them apart, as `get` does: a key
1210
+ pattern matches only a key, a slot pattern only a slot, an attr pattern only an attr.
1211
+ `**` reads keys, so it consumes only key segments; `*(.*,[*])` reads both:
1212
+
1213
+ >>> dotted.match('[*]', 'table')
1214
+ 'table'
1215
+ >>> dotted.match('[*]', 'table', strict=True)
1216
+ >>> dotted.match('*', '[0]', strict=True)
1217
+ >>> dotted.match('[*]', '[0]', strict=True)
1218
+ '[0]'
1219
+ >>> dotted.match('**.b', 'a[0].b', strict=True)
1220
+ >>> dotted.match('*(.*,[*]).b', 'a[0].b', strict=True)
1221
+ 'a[0].b'
1222
+
1200
1223
  <a id="paths"></a>
1201
1224
  ## Paths
1202
1225
 
@@ -655,6 +655,14 @@ depends on the data, so no part of the list covers it, and neither does
655
655
  >>> dotted.match('a[1:]', 'a[x=1]')
656
656
  >>> dotted.match('a[*]', 'a[x=1]')
657
657
 
658
+ A segment matches however it is read: `[*]` matches the key `table`, and `*` the slot
659
+ `[0]`. Pass `strict=True` to keep keys, slots and attrs apart, as
660
+ [strict mode](#strict-mode) does for `get`:
661
+
662
+ >>> dotted.match('[*]', 'table')
663
+ 'table'
664
+ >>> dotted.match('[*]', 'table', strict=True)
665
+
658
666
  <a id="replace"></a>
659
667
  ### Replace
660
668
 
@@ -1132,7 +1140,7 @@ Pass `strict=True` to enforce this separation:
1132
1140
  True
1133
1141
 
1134
1142
  Strict mode applies to all operations — `get`, `update`, `remove`, `has`, `expand`,
1135
- `pluck`, and their `_multi` variants. Mismatches silently return empty results, consistent
1143
+ `pluck`, `match`, and their `_multi` variants. Mismatches silently return empty results, consistent
1136
1144
  with dotted's safe traversal model:
1137
1145
 
1138
1146
  >>> dotted.has(d, '[0]', strict=True)
@@ -1147,6 +1155,21 @@ with dotted's safe traversal model:
1147
1155
  Use strict mode when your data mixes integer dict keys and list indices, and you need
1148
1156
  to distinguish between them.
1149
1157
 
1158
+ `match` and `match_multi` take `strict` too. By default a segment matches however it is
1159
+ read, so `[*]` matches a key and `*` a slot. Strict keeps them apart, as `get` does: a key
1160
+ pattern matches only a key, a slot pattern only a slot, an attr pattern only an attr.
1161
+ `**` reads keys, so it consumes only key segments; `*(.*,[*])` reads both:
1162
+
1163
+ >>> dotted.match('[*]', 'table')
1164
+ 'table'
1165
+ >>> dotted.match('[*]', 'table', strict=True)
1166
+ >>> dotted.match('*', '[0]', strict=True)
1167
+ >>> dotted.match('[*]', '[0]', strict=True)
1168
+ '[0]'
1169
+ >>> dotted.match('**.b', 'a[0].b', strict=True)
1170
+ >>> dotted.match('*(.*,[*]).b', 'a[0].b', strict=True)
1171
+ 'a[0].b'
1172
+
1150
1173
  <a id="paths"></a>
1151
1174
  ## Paths
1152
1175
 
@@ -443,6 +443,9 @@ class Key(AccessOp):
443
443
  except (IndexError, TypeError):
444
444
  return ()
445
445
 
446
+ def access_kind(self):
447
+ return 'key'
448
+
446
449
  def default(self):
447
450
  if self.is_pattern():
448
451
  return {}
@@ -609,6 +612,9 @@ class Attr(Key):
609
612
  result = self._concrete_fallback(node, result, filtered, settings)
610
613
  return result
611
614
 
615
+ def access_kind(self):
616
+ return 'attr'
617
+
612
618
  def default(self):
613
619
  o = types.SimpleNamespace()
614
620
  if self.is_pattern():
@@ -707,6 +713,9 @@ class Slot(Key):
707
713
 
708
714
  return self._items(node, keys, filtered, settings)
709
715
 
716
+ def access_kind(self):
717
+ return 'slot'
718
+
710
719
  def default(self):
711
720
  if isinstance(self.op, matchers.Numeric) and self.op.is_int():
712
721
  return []
@@ -900,6 +909,9 @@ class SliceFilter(BaseOp):
900
909
  def concrete(cls, val):
901
910
  return Slot.concrete(val)
902
911
 
912
+ def access_kind(self):
913
+ return 'slot'
914
+
903
915
  def is_pattern(self):
904
916
  return False
905
917
 
@@ -1013,6 +1025,8 @@ class Slice(SimpleOp):
1013
1025
  if step is not None:
1014
1026
  m += [s(step)]
1015
1027
  return '[' + ':'.join(m) + ']'
1028
+ def access_kind(self):
1029
+ return 'slot'
1016
1030
  def is_pattern(self):
1017
1031
  return False
1018
1032
  def is_slice(self):
@@ -880,6 +880,16 @@ def match(pattern, path, groups=False, partial=True, strict=False):
880
880
  >>> match('hello.*', 'hello.there.bye', groups='patterns')
881
881
  ('hello.there.bye', ('there.bye',))
882
882
 
883
+ A segment matches however it is read, unless strict=True keeps a key
884
+ to keys, a slot to slots and an attr to attrs, as strict mode does
885
+ for get:
886
+ >>> match('[*]', 'table')
887
+ 'table'
888
+ >>> match('[*]', 'table', strict=True)
889
+ >>> match('*', '[0]', strict=True)
890
+ >>> match('[*]', '[0]', strict=True)
891
+ '[0]'
892
+
883
893
  Group patterns match if any branch matches:
884
894
  >>> match('(a,b)', 'a')
885
895
  'a'
@@ -937,16 +947,16 @@ def match(pattern, path, groups=False, partial=True, strict=False):
937
947
  '*b'
938
948
  >>> match('*', '**')
939
949
  """
940
- return _match_parsed(parse(pattern), parse(path), path, groups, partial)
950
+ return _match_parsed(parse(pattern), parse(path), path, groups, partial, strict)
941
951
 
942
952
 
943
- def _match_parsed(pats, path_ops, path, groups, partial):
953
+ def _match_parsed(pats, path_ops, path, groups, partial, strict=False):
944
954
  """
945
955
  match() on parsed arguments. `path` is what a successful match returns.
946
956
  Each capture is the path segments one pattern segment matched, as the
947
957
  path writes them.
948
958
  """
949
- caps = _captures(pats, path_ops, partial, bool(groups))
959
+ caps = _captures(pats, path_ops, partial, bool(groups), strict)
950
960
  if not groups:
951
961
  return None if caps is None else path
952
962
  if caps is None:
@@ -957,18 +967,19 @@ def _match_parsed(pats, path_ops, path, groups, partial):
957
967
  return (path, tuple(results.assemble(ops) for ops, _ in caps))
958
968
 
959
969
 
960
- def _captures(pats, path_ops, partial, collect=True):
970
+ def _captures(pats, path_ops, partial, collect=True, strict=False):
961
971
  """
962
972
  The captures of the path that pats match, as base.match_ops gives
963
973
  them: (ops, is_pattern) pairs, each ops the path ops one pattern
964
974
  segment matched. None when pats don't match. Without collect, a
965
- match may give no captures.
975
+ match may give no captures. Under strict, a segment matches only
976
+ one read the same way: a key a key, a slot a slot, an attr an attr.
966
977
  """
967
978
  # Variadic ops (recursive, groups) consume variable-length path
968
979
  # segments — use the recursive matcher. On the path side they make
969
980
  # the path denote multiple expansions, which likewise needs it.
970
981
  if pats.variadic or path_ops.variadic:
971
- return base.match_ops(list(pats), list(path_ops), partial)
982
+ return base.match_ops(list(pats), list(path_ops), partial, strict)
972
983
 
973
984
  # one path segment per pattern segment; a partial match's last
974
985
  # capture runs to the end of the path
@@ -978,7 +989,10 @@ def _captures(pats, path_ops, partial, collect=True):
978
989
  return None
979
990
  caps = []
980
991
  for pop, kop in zip(pats, path_ops):
981
- if not pop.match(kop.match_target(), specials=True):
992
+ target = kop.match_target()
993
+ if strict and not base.same_access(pop, target):
994
+ return None
995
+ if not pop.match(target, specials=True):
982
996
  return None
983
997
  if collect:
984
998
  caps.append(((kop,), pop.is_pattern()))
@@ -998,7 +1012,7 @@ def match_multi(pattern, iterable, groups=False, partial=True, strict=False):
998
1012
  for p in iterable:
999
1013
  if pats is None:
1000
1014
  pats = parse(pattern)
1001
- yield _match_parsed(pats, parse(p), p, groups, partial)
1015
+ yield _match_parsed(pats, parse(p), p, groups, partial, strict)
1002
1016
 
1003
1017
  matches = _matches()
1004
1018
  if groups:
@@ -42,7 +42,7 @@ def has_any(gen):
42
42
  return any(True for _ in gen)
43
43
 
44
44
 
45
- def match_ops(pats, path_ops, partial):
45
+ def match_ops(pats, path_ops, partial, strict=False):
46
46
  """
47
47
  Match a list of pattern ops against a list of path ops.
48
48
  Returns a list of (ops, is_pattern) capture pairs on success, None
@@ -50,12 +50,13 @@ def match_ops(pats, path_ops, partial):
50
50
  path writes them. Dispatch is per-op on both sides: a variadic op at
51
51
  the head of the path (group, recursive) decides how the pattern must
52
52
  cover it via do_match_path; otherwise the head pattern op decides
53
- how many path segments it consumes via do_match.
53
+ how many path segments it consumes via do_match. Under strict, a
54
+ segment matches only one read the same way (see same_access).
54
55
  """
55
56
  if path_ops and path_ops[0].is_variadic():
56
- return path_ops[0].do_match_path(list(pats), list(path_ops[1:]), partial)
57
+ return path_ops[0].do_match_path(list(pats), list(path_ops[1:]), partial, strict)
57
58
  if pats:
58
- return pats[0].do_match(pats[1:], path_ops, partial)
59
+ return pats[0].do_match(pats[1:], path_ops, partial, strict)
59
60
  if not path_ops:
60
61
  return []
61
62
  if partial:
@@ -84,6 +85,17 @@ def capture(path_ops, is_pat, rest):
84
85
  return [(ops, is_pat)] + rest
85
86
 
86
87
 
88
+ def same_access(pat, op):
89
+ """
90
+ True if pattern op `pat` and path op `op` read a node the same way,
91
+ as strict mode asks: a key only a key, a slot only a slot, an attr
92
+ only an attr. An op with no access of its own (a group) passes.
93
+ """
94
+ a = pat.access_kind()
95
+ b = op.access_kind()
96
+ return a is None or b is None or a == b
97
+
98
+
87
99
  class MatchResult:
88
100
  def __init__(self, val):
89
101
  self.val = val
@@ -132,6 +144,13 @@ class Op:
132
144
  return self
133
145
  def scrub(self, node):
134
146
  return node
147
+ def access_kind(self):
148
+ """
149
+ How this op reads a node: 'key', 'slot' or 'attr', or None when it
150
+ has no one way (a group, a recursive op). Strict mode keeps the
151
+ three apart (see same_access).
152
+ """
153
+ return None
135
154
  def match_target(self):
136
155
  """
137
156
  What a pattern matches this path op as: the op itself. A
@@ -533,7 +552,7 @@ class TraversalOp(Op):
533
552
  val = getattr(getattr(self, 'op', self), 'value', self)
534
553
  return has_any(matcher.matches((val,)))
535
554
 
536
- def do_match(self, rest_pats, path_ops, partial):
555
+ def do_match(self, rest_pats, path_ops, partial, strict=False):
537
556
  """
538
557
  Match this op against exactly one path segment, then continue with
539
558
  the remaining pattern ops. Variadic ops (recursive, groups)
@@ -541,9 +560,12 @@ class TraversalOp(Op):
541
560
  """
542
561
  if not path_ops:
543
562
  return None
544
- if not self.match(path_ops[0].match_target(), specials=True):
563
+ target = path_ops[0].match_target()
564
+ if strict and not same_access(self, target):
565
+ return None
566
+ if not self.match(target, specials=True):
545
567
  return None
546
- rest = match_ops(rest_pats, path_ops[1:], partial)
568
+ rest = match_ops(rest_pats, path_ops[1:], partial, strict)
547
569
  if rest is None:
548
570
  return None
549
571
  return capture(path_ops[:1], self.is_pattern(), rest)
@@ -190,7 +190,7 @@ class OpGroup(base.TraversalOp):
190
190
  def operator(self, top=False):
191
191
  return self._render(top)
192
192
 
193
- def do_match(self, rest_pats, path_ops, partial):
193
+ def do_match(self, rest_pats, path_ops, partial, strict=False):
194
194
  """
195
195
  Match a concrete path against this group: the path matches if it
196
196
  matches any branch followed by the remaining pattern ops. A single
@@ -205,16 +205,16 @@ class OpGroup(base.TraversalOp):
205
205
  for branch in base.branches_only(self.branches):
206
206
  branch_ops = list(branch)
207
207
  for n in range(len(path_ops) + 1):
208
- consumed = base.match_ops(branch_ops, path_ops[:n], False)
208
+ consumed = base.match_ops(branch_ops, path_ops[:n], False, strict)
209
209
  if consumed is None:
210
210
  continue
211
- rest = base.match_ops(list(rest_pats), path_ops[n:], partial)
211
+ rest = base.match_ops(list(rest_pats), path_ops[n:], partial, strict)
212
212
  if rest is None:
213
213
  continue
214
214
  return base.capture(path_ops[:n], True, rest)
215
215
  return None
216
216
 
217
- def do_match_path(self, pats, rest_path, partial):
217
+ def do_match_path(self, pats, rest_path, partial, strict=False):
218
218
  """
219
219
  Match when this group appears on the *path* side. The path
220
220
  denotes every expansion of the group's branches, so the pattern
@@ -231,19 +231,19 @@ class OpGroup(base.TraversalOp):
231
231
  """
232
232
  if not pats and partial:
233
233
  return base.leftover([self] + list(rest_path))
234
- fallback = self._verify_covered(pats, rest_path, partial)
234
+ fallback = self._verify_covered(pats, rest_path, partial, strict)
235
235
  if fallback is None:
236
236
  return None
237
- r = self._aligned_captures(pats, rest_path, partial)
237
+ r = self._aligned_captures(pats, rest_path, partial, strict)
238
238
  if r is not None:
239
239
  return r
240
240
  if pats and pats[0].is_variadic():
241
- r = pats[0].do_match(pats[1:], [self] + list(rest_path), partial)
241
+ r = pats[0].do_match(pats[1:], [self] + list(rest_path), partial, strict)
242
242
  if r is not None:
243
243
  return r
244
244
  return fallback
245
245
 
246
- def _verify_covered(self, pats, rest_path, partial):
246
+ def _verify_covered(self, pats, rest_path, partial, strict=False):
247
247
  """
248
248
  Subsumption check over expansions: splice each branch into the
249
249
  path and match. Returns the first branch's result (the capture
@@ -251,16 +251,16 @@ class OpGroup(base.TraversalOp):
251
251
  """
252
252
  first = base.marker
253
253
  for branch in base.branches_only(self.branches):
254
- r = base.match_ops(pats, list(branch) + list(rest_path), partial)
254
+ r = base.match_ops(pats, list(branch) + list(rest_path), partial, strict)
255
255
  if r is None:
256
256
  return None
257
257
  if first is base.marker:
258
258
  first = r
259
259
  if first is base.marker:
260
- return base.match_ops(pats, list(rest_path), partial)
260
+ return base.match_ops(pats, list(rest_path), partial, strict)
261
261
  return first
262
262
 
263
- def _aligned_captures(self, pats, rest_path, partial):
263
+ def _aligned_captures(self, pats, rest_path, partial, strict=False):
264
264
  """
265
265
  Group-as-itself captures: find a pattern prefix that covers the
266
266
  branch set exactly (or up to a partial tail when the pattern
@@ -270,20 +270,20 @@ class OpGroup(base.TraversalOp):
270
270
  for k in range(1, len(pats) + 1):
271
271
  head = list(pats[:k])
272
272
  tail_partial = partial and k == len(pats) and not rest_path
273
- if not self._covers_branches(head, tail_partial):
273
+ if not self._covers_branches(head, tail_partial, strict):
274
274
  continue
275
- rest = base.match_ops(list(pats[k:]), list(rest_path), partial)
275
+ rest = base.match_ops(list(pats[k:]), list(rest_path), partial, strict)
276
276
  if rest is None:
277
277
  continue
278
278
  is_pat = any(p.is_pattern() for p in head)
279
279
  return base.capture([self], is_pat, rest)
280
280
  return None
281
281
 
282
- def _covers_branches(self, head_pats, tail_partial=False):
282
+ def _covers_branches(self, head_pats, tail_partial=False, strict=False):
283
283
  """
284
284
  True if head_pats covers every branch of this group.
285
285
  """
286
- return all(base.match_ops(head_pats, list(b), tail_partial) is not None
286
+ return all(base.match_ops(head_pats, list(b), tail_partial, strict) is not None
287
287
  for b in base.branches_only(self.branches))
288
288
 
289
289
  def covered_by(self, matcher):
@@ -658,23 +658,23 @@ class OpGroupAnd(OpGroup):
658
658
  def __repr__(self):
659
659
  return self._render(top=True)
660
660
 
661
- def _verify_covered(self, pats, rest_path, partial):
661
+ def _verify_covered(self, pats, rest_path, partial, strict=False):
662
662
  """
663
663
  A conjunction's expansions are the intersection of its
664
664
  branches', so a pattern covering any single branch covers the
665
665
  whole (sufficient, conservatively incomplete).
666
666
  """
667
667
  for branch in base.branches_only(self.branches):
668
- r = base.match_ops(pats, list(branch) + list(rest_path), partial)
668
+ r = base.match_ops(pats, list(branch) + list(rest_path), partial, strict)
669
669
  if r is not None:
670
670
  return r
671
671
  return None
672
672
 
673
- def _covers_branches(self, head_pats, tail_partial=False):
673
+ def _covers_branches(self, head_pats, tail_partial=False, strict=False):
674
674
  """
675
675
  Any single covered branch suffices for a conjunction.
676
676
  """
677
- return any(base.match_ops(head_pats, list(b), tail_partial) is not None
677
+ return any(base.match_ops(head_pats, list(b), tail_partial, strict) is not None
678
678
  for b in base.branches_only(self.branches))
679
679
 
680
680
  def push_children(self, stack, frame, paths):
@@ -890,24 +890,27 @@ class OpGroupNot(OpGroup):
890
890
  def default(self):
891
891
  return self._leaf().default()
892
892
 
893
- def do_match(self, rest_pats, path_ops, partial):
893
+ def do_match(self, rest_pats, path_ops, partial, strict=False):
894
894
  """
895
895
  Match the segments of one subtree of the complement: they follow
896
896
  the inner branch op by op until one does not match, and that one
897
897
  ends the subtree; then continue with the remaining ops. A path
898
898
  the whole branch matches is in the negated pattern, not out of it.
899
+ Under strict, each segment is read as the inner op it meets is.
899
900
  """
900
901
  inner = self.inner
901
902
  for i, kop in enumerate(path_ops[:len(inner)]):
902
- if base.match_ops([inner[i]], [kop], False) is not None:
903
+ if strict and not base.same_access(inner[i], kop.match_target()):
904
+ return None
905
+ if base.match_ops([inner[i]], [kop], False, strict) is not None:
903
906
  continue
904
- rest = base.match_ops(rest_pats, path_ops[i + 1:], partial)
907
+ rest = base.match_ops(rest_pats, path_ops[i + 1:], partial, strict)
905
908
  if rest is None:
906
909
  return None
907
910
  return base.capture(path_ops[:i + 1], True, rest)
908
911
  return None
909
912
 
910
- def do_match_path(self, pats, rest_path, partial):
913
+ def do_match_path(self, pats, rest_path, partial, strict=False):
911
914
  """
912
915
  Match when this negation appears on the *path* side. It denotes
913
916
  every segment its inner pattern excludes — an open set — so it
@@ -919,7 +922,7 @@ class OpGroupNot(OpGroup):
919
922
  head = pats[0]
920
923
  if head != self and not self._wildcard_covers(head):
921
924
  return None
922
- rest = base.match_ops(pats[1:], rest_path, partial)
925
+ rest = base.match_ops(pats[1:], rest_path, partial, strict)
923
926
  if rest is None:
924
927
  return None
925
928
  return base.capture([self], True, rest)
@@ -1018,13 +1021,13 @@ class Pack(base.TraversalOp):
1018
1021
  return None
1019
1022
  return base.MatchResult(self)
1020
1023
 
1021
- def do_match(self, rest_pats, path_ops, partial):
1024
+ def do_match(self, rest_pats, path_ops, partial, strict=False):
1022
1025
  """
1023
1026
  One segment, matched by equality (see match).
1024
1027
  """
1025
1028
  if not path_ops or not self.match(path_ops[0]):
1026
1029
  return None
1027
- rest = base.match_ops(rest_pats, path_ops[1:], partial)
1030
+ rest = base.match_ops(rest_pats, path_ops[1:], partial, strict)
1028
1031
  if rest is None:
1029
1032
  return None
1030
1033
  return base.capture(path_ops[:1], False, rest)
@@ -148,22 +148,41 @@ class Recursive(BaseOp):
148
148
  def match(self, op, specials=False):
149
149
  return self.inner.matchable(op, specials=specials)
150
150
 
151
- def do_match(self, rest_pats, path_ops, partial):
151
+ def do_match(self, rest_pats, path_ops, partial, strict=False):
152
152
  """
153
153
  Match by consuming 1..N path segments via backtracking. Each
154
154
  consumed segment must match the inner pattern (chain-following);
155
- stop extending once a segment fails.
155
+ stop extending once a segment fails. Under strict, each must
156
+ also be read the way one of this op's accessors reads a node.
156
157
  """
157
158
  for n in range(1, len(path_ops) + 1):
158
- if not path_ops[n - 1].covered_by(self.inner):
159
+ seg = path_ops[n - 1]
160
+ if strict and not self._reads(seg):
159
161
  return None
160
- rest = base.match_ops(rest_pats, path_ops[n:], partial)
162
+ if not seg.covered_by(self.inner):
163
+ return None
164
+ rest = base.match_ops(rest_pats, path_ops[n:], partial, strict)
161
165
  if rest is None:
162
166
  continue
163
167
  return base.capture(path_ops[:n], True, rest)
164
168
  return None
165
169
 
166
- def do_match_path(self, pats, rest_path, partial):
170
+ def _reads(self, op):
171
+ """
172
+ True if one of this op's accessors reads a node the way path op
173
+ `op` does: ** reads keys, *(.*,[*]) keys and slots.
174
+ """
175
+ kind = op.match_target().access_kind()
176
+ return kind is None or kind in self._access_kinds
177
+
178
+ @utils.lazyprop
179
+ def _access_kinds(self):
180
+ """
181
+ How this op's accessors read a node (see base.Op.access_kind).
182
+ """
183
+ return {op.access_kind() for branch in base.branches_only(self._effective_branches()) for op in branch}
184
+
185
+ def do_match_path(self, pats, rest_path, partial, strict=False):
167
186
  """
168
187
  Match when this recursive op appears on the *path* side. It
169
188
  denotes unboundedly many expansions, so only a pattern segment
@@ -179,9 +198,9 @@ class Recursive(BaseOp):
179
198
  return None
180
199
  if not self._subsumed_by(head):
181
200
  return None
182
- rest = base.match_ops(pats[1:], rest_path, partial)
201
+ rest = base.match_ops(pats[1:], rest_path, partial, strict)
183
202
  if rest is None:
184
- rest = base.match_ops(pats, rest_path, partial)
203
+ rest = base.match_ops(pats, rest_path, partial, strict)
185
204
  if rest is None:
186
205
  return None
187
206
  return base.capture([self], True, rest)
@@ -85,22 +85,28 @@ class Wrap(base.TraversalOp):
85
85
  """
86
86
  return self.inner.leaf_op()
87
87
 
88
- def do_match(self, rest_pats, path_ops, partial):
88
+ def access_kind(self):
89
+ """
90
+ A wrap decorates; it reads a node as the wrapped op does.
91
+ """
92
+ return self.inner.access_kind()
93
+
94
+ def do_match(self, rest_pats, path_ops, partial, strict=False):
89
95
  """
90
96
  Variadic inners (recursive ops, groups) decide their own segment
91
97
  consumption; otherwise match one segment via this wrap's match.
92
98
  """
93
99
  if self.is_variadic():
94
- return self.inner.do_match(rest_pats, path_ops, partial)
95
- return super().do_match(rest_pats, path_ops, partial)
100
+ return self.inner.do_match(rest_pats, path_ops, partial, strict)
101
+ return super().do_match(rest_pats, path_ops, partial, strict)
96
102
 
97
- def do_match_path(self, pats, rest_path, partial):
103
+ def do_match_path(self, pats, rest_path, partial, strict=False):
98
104
  """
99
105
  Delegate path-side matching to the wrapped op (only reached for
100
106
  variadic inners, via is_variadic). A capture of the wrapped op
101
107
  is a capture of this one: the segment as the path writes it.
102
108
  """
103
- r = self.inner.do_match_path(pats, rest_path, partial)
109
+ r = self.inner.do_match_path(pats, rest_path, partial, strict)
104
110
  if r is None:
105
111
  return None
106
112
  inner = self.inner
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dotted_notation
3
- Version: 0.55.4
3
+ Version: 0.55.5
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-Expression: MIT
@@ -705,6 +705,14 @@ depends on the data, so no part of the list covers it, and neither does
705
705
  >>> dotted.match('a[1:]', 'a[x=1]')
706
706
  >>> dotted.match('a[*]', 'a[x=1]')
707
707
 
708
+ A segment matches however it is read: `[*]` matches the key `table`, and `*` the slot
709
+ `[0]`. Pass `strict=True` to keep keys, slots and attrs apart, as
710
+ [strict mode](#strict-mode) does for `get`:
711
+
712
+ >>> dotted.match('[*]', 'table')
713
+ 'table'
714
+ >>> dotted.match('[*]', 'table', strict=True)
715
+
708
716
  <a id="replace"></a>
709
717
  ### Replace
710
718
 
@@ -1182,7 +1190,7 @@ Pass `strict=True` to enforce this separation:
1182
1190
  True
1183
1191
 
1184
1192
  Strict mode applies to all operations — `get`, `update`, `remove`, `has`, `expand`,
1185
- `pluck`, and their `_multi` variants. Mismatches silently return empty results, consistent
1193
+ `pluck`, `match`, and their `_multi` variants. Mismatches silently return empty results, consistent
1186
1194
  with dotted's safe traversal model:
1187
1195
 
1188
1196
  >>> dotted.has(d, '[0]', strict=True)
@@ -1197,6 +1205,21 @@ with dotted's safe traversal model:
1197
1205
  Use strict mode when your data mixes integer dict keys and list indices, and you need
1198
1206
  to distinguish between them.
1199
1207
 
1208
+ `match` and `match_multi` take `strict` too. By default a segment matches however it is
1209
+ read, so `[*]` matches a key and `*` a slot. Strict keeps them apart, as `get` does: a key
1210
+ pattern matches only a key, a slot pattern only a slot, an attr pattern only an attr.
1211
+ `**` reads keys, so it consumes only key segments; `*(.*,[*])` reads both:
1212
+
1213
+ >>> dotted.match('[*]', 'table')
1214
+ 'table'
1215
+ >>> dotted.match('[*]', 'table', strict=True)
1216
+ >>> dotted.match('*', '[0]', strict=True)
1217
+ >>> dotted.match('[*]', '[0]', strict=True)
1218
+ '[0]'
1219
+ >>> dotted.match('**.b', 'a[0].b', strict=True)
1220
+ >>> dotted.match('*(.*,[*]).b', 'a[0].b', strict=True)
1221
+ 'a[0].b'
1222
+
1200
1223
  <a id="paths"></a>
1201
1224
  ## Paths
1202
1225
 
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "dotted_notation"
9
- version = "0.55.4"
9
+ version = "0.55.5"
10
10
  description = "Dotted notation for safe nested data traversal with optional chaining, pattern matching, and transforms"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.6"