dotted-notation 0.56.0__tar.gz → 0.56.2__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.56.0 → dotted_notation-0.56.2}/CHANGELOG.md +33 -0
  2. {dotted_notation-0.56.0/dotted_notation.egg-info → dotted_notation-0.56.2}/PKG-INFO +64 -6
  3. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/README.md +63 -5
  4. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/translators/core.py +55 -6
  5. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/translators/spark_pyspark.py +813 -5
  6. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/translators/sql_pg.py +92 -10
  7. {dotted_notation-0.56.0 → dotted_notation-0.56.2/dotted_notation.egg-info}/PKG-INFO +64 -6
  8. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/pyproject.toml +1 -1
  9. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/LICENSE +0 -0
  10. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/MANIFEST.in +0 -0
  11. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/__init__.py +0 -0
  12. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/__main__.py +0 -0
  13. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/access.pxd +0 -0
  14. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/access.py +0 -0
  15. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/api.py +0 -0
  16. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/base.pxd +0 -0
  17. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/base.py +0 -0
  18. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/cli/__init__.py +0 -0
  19. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/cli/_compat.py +0 -0
  20. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/cli/formats.py +0 -0
  21. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/cli/main.py +0 -0
  22. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/containers.py +0 -0
  23. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/engine.pxd +0 -0
  24. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/engine.py +0 -0
  25. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/filters.pxd +0 -0
  26. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/filters.py +0 -0
  27. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/grammar.py +0 -0
  28. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/groups.pxd +0 -0
  29. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/groups.py +0 -0
  30. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/matchers.pxd +0 -0
  31. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/matchers.py +0 -0
  32. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/native.py +0 -0
  33. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/predicates.py +0 -0
  34. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/recursive.pxd +0 -0
  35. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/recursive.py +0 -0
  36. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/results.py +0 -0
  37. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/transforms.py +0 -0
  38. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/translators/__init__.py +0 -0
  39. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/translators/spark.py +0 -0
  40. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/translators/sql.py +0 -0
  41. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/utils.py +0 -0
  42. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/utypes.py +0 -0
  43. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/wrappers.pxd +0 -0
  44. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted/wrappers.py +0 -0
  45. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted_notation.egg-info/SOURCES.txt +0 -0
  46. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted_notation.egg-info/dependency_links.txt +0 -0
  47. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted_notation.egg-info/entry_points.txt +0 -0
  48. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted_notation.egg-info/requires.txt +0 -0
  49. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/dotted_notation.egg-info/top_level.txt +0 -0
  50. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/setup.cfg +0 -0
  51. {dotted_notation-0.56.0 → dotted_notation-0.56.2}/setup.py +0 -0
@@ -3,6 +3,39 @@
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.56.2]
7
+
8
+ ### Added
9
+ - `sqlize` and `sparkize` write through groups, as dotted's `update`
10
+ does: `(a, b)` writes each branch where it matches, on the node the
11
+ branches before it wrote, and builds the last concrete one where none
12
+ does; `(a&b)` writes every branch, where each matches or can be built;
13
+ `(a, b)?` writes the first that matches; a cut ends the branches after
14
+ one that matched. So `emails[(*&email="x"#, +)]` writes the email
15
+ that's there, else appends one, and `(name.~first#, name.first)` sets
16
+ `first` only where it's missing. A soft cut in a write, and a group at
17
+ the top of a path, still raise (#75).
18
+
19
+ ## [0.56.1]
20
+
21
+ ### Added
22
+ - `sparkize`'s `r.as_update(value)`, the write of `value` at a column
23
+ path's matches as dotted's `update` does it, as `sqlize`'s
24
+ `as_update` writes it: `build` makes it a dict for `df.withColumns`,
25
+ `df.withColumns(r.build(r.as_update('admin'), schema=df.schema))`.
26
+ Each node is written by its Spark type: a struct's field takes the
27
+ written value's type, a map's values and a list's elements share one.
28
+ Where Spark can't hold what dotted writes, as a null struct dotted
29
+ makes a dict of fewer keys, or where dotted's update raises, the job
30
+ fails with a `dotted update: …` message. Groups, `!`, `**` and slices
31
+ in a write raise, and a slot on a str fails the job, as in `sqlize`
32
+ (#75).
33
+
34
+ ### Fixed
35
+ - `sqlize`'s `as_update` writes nothing under `~` at a string, and
36
+ nothing for `.*` at an array or a string, as dotted's update does;
37
+ it failed.
38
+
6
39
  ## [0.56.0]
7
40
 
8
41
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dotted_notation
3
- Version: 0.56.0
3
+ Version: 0.56.2
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
@@ -3902,6 +3902,13 @@ Python's `in` tells. For a column path it is the assignments, for an
3902
3902
  >>> args[-1]
3903
3903
  '"admin"'
3904
3904
 
3905
+ A group writes as `update` does: `(a, b)` each branch where it
3906
+ matches, on the node the branches before it wrote, the last concrete
3907
+ one built where none does; `(a&b)` every branch, where each matches or
3908
+ can be built; `(a, b)?` the first that matches; and a cut ends the
3909
+ branches after one that matched, so `emails[(*&email="x"#, +)]` writes
3910
+ the email that's there, else appends one.
3911
+
3905
3912
  A value is a literal, sent as a parameter, or a `Raw` / `Col` SQL
3906
3913
  expression. A transform at the end of the path, `data.user.age|int`,
3907
3914
  applies to a literal value, as dotted's does; on a SQL expression it
@@ -3913,7 +3920,8 @@ Not yet supported (`TranslationError`):
3913
3920
  - Regex keys, `data./prefix_\d+/.field`; references inside pattern
3914
3921
  paths; a `**` with depths or accessors; first filters, `[*&a=1?]`
3915
3922
  - Transforms other than `int`, `float` and `str`, or with arguments
3916
- - In a write: groups, `!`, `**` and slices; a table search
3923
+ - In a write: a soft cut, `!`, `**` and slices; a group at the top of
3924
+ a path; a table search
3917
3925
 
3918
3926
  <a id="sqlize-table-search"></a>
3919
3927
  ### `sqlize` table search
@@ -4183,8 +4191,8 @@ A `SQLFragment` carries:
4183
4191
  - Returns a `SQLFragment`: for a column path, the assignments for an
4184
4192
  `UPDATE ... SET`, each column's new value as dotted's `update` writes
4185
4193
  `value` at the path's matches (see *Writes* above). Build it with
4186
- `r.build`. A table search, and groups, `!`, `**` and slices in the
4187
- path, raise `TranslationError`.
4194
+ `r.build`. A table search, and a soft cut, `!`, `**` and slices in
4195
+ the path, raise `TranslationError`.
4188
4196
 
4189
4197
  The `Resolver.build(sql, paramstyle='...', **bindings)` classmethod is
4190
4198
  retained as a low-level escape hatch that takes an explicit paramstyle
@@ -4362,6 +4370,47 @@ A `Column` can't hold a placeholder, so `r.where` is a
4362
4370
  b = dotted.sparkize('status = "active"')
4363
4371
  df.where(a.build(a.where & b.where, schema=df.schema, min_age=30))
4364
4372
 
4373
+ ### Writes (`as_update`)
4374
+
4375
+ `r.as_update(value)` is the write of `value` at the path's matches, as
4376
+ dotted's `update` does it, and as `sqlize`'s `as_update` writes it.
4377
+ `build` makes it a dict of each column the write touches to its new
4378
+ value, for `df.withColumns`:
4379
+
4380
+ r = dotted.sparkize('data.user.role')
4381
+ df = df.withColumns(r.build(r.as_update('admin'), schema=df.schema))
4382
+
4383
+ The write is:
4384
+ - `value` at each match;
4385
+ - along literal keys and slots, the nodes the path lacks built, a null
4386
+ one replaced, as dotted builds them, and a slot past the end
4387
+ appending;
4388
+ - a pattern, filter or guard writing only what is there and passes;
4389
+ - `~` holding a segment back;
4390
+ - `[+]` appending, and `[+?]` where the list doesn't hold the value, as
4391
+ Python's `in` tells.
4392
+
4393
+ A value is a literal, or a `Column`, read by its type; a transform at
4394
+ the end of the path applies to a literal. A struct's field takes the
4395
+ written value's type; a map's values, and a list's elements, share
4396
+ one. Where Spark can't hold what dotted writes, the job fails, with a
4397
+ `dotted update: …` message, where a row has it:
4398
+ - a null struct, which dotted makes a dict of only the keys the path
4399
+ names;
4400
+ - a field added to some of a list's structs and not to others;
4401
+ - a str written among a map's ints.
4402
+
4403
+ A group writes as dotted's `update` does, as in `sqlize`: `(a, b)` each branch where it
4404
+ matches, on the node the branches before it wrote, the last concrete
4405
+ one built where none does; `(a&b)` every branch, where each matches or
4406
+ can be built; `(a, b)?` the first that matches; and a cut ends the
4407
+ branches after one that matched, so `emails[(*&email="x"#, +)]` writes
4408
+ the email that's there, else appends one.
4409
+
4410
+ So does a write where dotted's update raises: a key on a list, an
4411
+ index before its start. A slot on a str, which dotted writes, fails
4412
+ too for now, as in `sqlize` (#75).
4413
+
4365
4414
  <a id="sparkize-table-search"></a>
4366
4415
  ### `sparkize` table search
4367
4416
 
@@ -4406,7 +4455,8 @@ Not yet supported (`TranslationError`):
4406
4455
  - Comparing a `DECIMAL` with a float `Column`; `str()` or a regex of a
4407
4456
  timestamp, whose Python value depends on the session's time zone;
4408
4457
  reading into a binary value
4409
- - Writes
4458
+ - In a write: a soft cut, `!`, `**` and slices; a group at the top of
4459
+ a path; a table search; a column the schema lacks
4410
4460
 
4411
4461
  ### API reference
4412
4462
 
@@ -4425,13 +4475,21 @@ Not yet supported (`TranslationError`):
4425
4475
  `r.build(fragment, schema=None, **bindings)`
4426
4476
 
4427
4477
  - `fragment` — a `ColumnFragment` (`r.where`, `r.select`, or a
4428
- composition of fragments).
4478
+ composition of fragments), or `r.as_update(value)`, which builds to a
4479
+ dict of column name to `Column`.
4429
4480
  - `schema` — **required**. The schema of the DataFrame the Column
4430
4481
  reads, `df.schema`: a path reads each node by its type.
4431
4482
  - `**bindings` — values for substitutions, keyed by original
4432
4483
  substitution name. An unknown or missing binding raises
4433
4484
  `TranslationError`.
4434
4485
 
4486
+ `r.as_update(value)`
4487
+
4488
+ - `value` — a literal, or a Spark `Column`, read by its type.
4489
+ - Returns a fragment `build` makes into a dict of each column the write
4490
+ touches, by name, to its new value, for `df.withColumns` (see
4491
+ *Writes* above).
4492
+
4435
4493
  Translation never imports pyspark; only `build` does.
4436
4494
 
4437
4495
  <a id="constants-and-exceptions"></a>
@@ -3852,6 +3852,13 @@ Python's `in` tells. For a column path it is the assignments, for an
3852
3852
  >>> args[-1]
3853
3853
  '"admin"'
3854
3854
 
3855
+ A group writes as `update` does: `(a, b)` each branch where it
3856
+ matches, on the node the branches before it wrote, the last concrete
3857
+ one built where none does; `(a&b)` every branch, where each matches or
3858
+ can be built; `(a, b)?` the first that matches; and a cut ends the
3859
+ branches after one that matched, so `emails[(*&email="x"#, +)]` writes
3860
+ the email that's there, else appends one.
3861
+
3855
3862
  A value is a literal, sent as a parameter, or a `Raw` / `Col` SQL
3856
3863
  expression. A transform at the end of the path, `data.user.age|int`,
3857
3864
  applies to a literal value, as dotted's does; on a SQL expression it
@@ -3863,7 +3870,8 @@ Not yet supported (`TranslationError`):
3863
3870
  - Regex keys, `data./prefix_\d+/.field`; references inside pattern
3864
3871
  paths; a `**` with depths or accessors; first filters, `[*&a=1?]`
3865
3872
  - Transforms other than `int`, `float` and `str`, or with arguments
3866
- - In a write: groups, `!`, `**` and slices; a table search
3873
+ - In a write: a soft cut, `!`, `**` and slices; a group at the top of
3874
+ a path; a table search
3867
3875
 
3868
3876
  <a id="sqlize-table-search"></a>
3869
3877
  ### `sqlize` table search
@@ -4133,8 +4141,8 @@ A `SQLFragment` carries:
4133
4141
  - Returns a `SQLFragment`: for a column path, the assignments for an
4134
4142
  `UPDATE ... SET`, each column's new value as dotted's `update` writes
4135
4143
  `value` at the path's matches (see *Writes* above). Build it with
4136
- `r.build`. A table search, and groups, `!`, `**` and slices in the
4137
- path, raise `TranslationError`.
4144
+ `r.build`. A table search, and a soft cut, `!`, `**` and slices in
4145
+ the path, raise `TranslationError`.
4138
4146
 
4139
4147
  The `Resolver.build(sql, paramstyle='...', **bindings)` classmethod is
4140
4148
  retained as a low-level escape hatch that takes an explicit paramstyle
@@ -4312,6 +4320,47 @@ A `Column` can't hold a placeholder, so `r.where` is a
4312
4320
  b = dotted.sparkize('status = "active"')
4313
4321
  df.where(a.build(a.where & b.where, schema=df.schema, min_age=30))
4314
4322
 
4323
+ ### Writes (`as_update`)
4324
+
4325
+ `r.as_update(value)` is the write of `value` at the path's matches, as
4326
+ dotted's `update` does it, and as `sqlize`'s `as_update` writes it.
4327
+ `build` makes it a dict of each column the write touches to its new
4328
+ value, for `df.withColumns`:
4329
+
4330
+ r = dotted.sparkize('data.user.role')
4331
+ df = df.withColumns(r.build(r.as_update('admin'), schema=df.schema))
4332
+
4333
+ The write is:
4334
+ - `value` at each match;
4335
+ - along literal keys and slots, the nodes the path lacks built, a null
4336
+ one replaced, as dotted builds them, and a slot past the end
4337
+ appending;
4338
+ - a pattern, filter or guard writing only what is there and passes;
4339
+ - `~` holding a segment back;
4340
+ - `[+]` appending, and `[+?]` where the list doesn't hold the value, as
4341
+ Python's `in` tells.
4342
+
4343
+ A value is a literal, or a `Column`, read by its type; a transform at
4344
+ the end of the path applies to a literal. A struct's field takes the
4345
+ written value's type; a map's values, and a list's elements, share
4346
+ one. Where Spark can't hold what dotted writes, the job fails, with a
4347
+ `dotted update: …` message, where a row has it:
4348
+ - a null struct, which dotted makes a dict of only the keys the path
4349
+ names;
4350
+ - a field added to some of a list's structs and not to others;
4351
+ - a str written among a map's ints.
4352
+
4353
+ A group writes as dotted's `update` does, as in `sqlize`: `(a, b)` each branch where it
4354
+ matches, on the node the branches before it wrote, the last concrete
4355
+ one built where none does; `(a&b)` every branch, where each matches or
4356
+ can be built; `(a, b)?` the first that matches; and a cut ends the
4357
+ branches after one that matched, so `emails[(*&email="x"#, +)]` writes
4358
+ the email that's there, else appends one.
4359
+
4360
+ So does a write where dotted's update raises: a key on a list, an
4361
+ index before its start. A slot on a str, which dotted writes, fails
4362
+ too for now, as in `sqlize` (#75).
4363
+
4315
4364
  <a id="sparkize-table-search"></a>
4316
4365
  ### `sparkize` table search
4317
4366
 
@@ -4356,7 +4405,8 @@ Not yet supported (`TranslationError`):
4356
4405
  - Comparing a `DECIMAL` with a float `Column`; `str()` or a regex of a
4357
4406
  timestamp, whose Python value depends on the session's time zone;
4358
4407
  reading into a binary value
4359
- - Writes
4408
+ - In a write: a soft cut, `!`, `**` and slices; a group at the top of
4409
+ a path; a table search; a column the schema lacks
4360
4410
 
4361
4411
  ### API reference
4362
4412
 
@@ -4375,13 +4425,21 @@ Not yet supported (`TranslationError`):
4375
4425
  `r.build(fragment, schema=None, **bindings)`
4376
4426
 
4377
4427
  - `fragment` — a `ColumnFragment` (`r.where`, `r.select`, or a
4378
- composition of fragments).
4428
+ composition of fragments), or `r.as_update(value)`, which builds to a
4429
+ dict of column name to `Column`.
4379
4430
  - `schema` — **required**. The schema of the DataFrame the Column
4380
4431
  reads, `df.schema`: a path reads each node by its type.
4381
4432
  - `**bindings` — values for substitutions, keyed by original
4382
4433
  substitution name. An unknown or missing binding raises
4383
4434
  `TranslationError`.
4384
4435
 
4436
+ `r.as_update(value)`
4437
+
4438
+ - `value` — a literal, or a Spark `Column`, read by its type.
4439
+ - Returns a fragment `build` makes into a dict of each column the write
4440
+ touches, by name, to its new value, for `df.withColumns` (see
4441
+ *Writes* above).
4442
+
4385
4443
  Translation never imports pyspark; only `build` does.
4386
4444
 
4387
4445
  <a id="constants-and-exceptions"></a>
@@ -465,13 +465,15 @@ class Hooks:
465
465
  return self.other(m, *args)
466
466
 
467
467
 
468
- def _branches(group_op, kind):
468
+ def _branches(group_op, kind, whole=False):
469
469
  """
470
470
  A group of `kind`'s branches, and per branch whether a cut follows
471
471
  it and whether a soft cut does. Neither changes anything in a
472
472
  first-match group, whose first match ends it anyway. In a
473
- conjunction a cut ends the branches: the conjunction holds only
474
- where the cut branch matched, and there the cut stops it.
473
+ conjunction a read ends the branches at a cut: the conjunction holds
474
+ only where the cut branch matched, and there the cut stops it. A
475
+ write, `whole`, keeps them and their cuts: it builds a cut branch
476
+ that doesn't match and goes on.
475
477
  """
476
478
  branches = []
477
479
  cuts = []
@@ -488,10 +490,10 @@ def _branches(group_op, kind):
488
490
  softs.append(False)
489
491
  if kind == 'first':
490
492
  return tuple(branches), (False,) * len(branches), (False,) * len(branches)
491
- if kind == 'and' and True in cuts:
493
+ if kind == 'and' and not whole and True in cuts:
492
494
  n = cuts.index(True) + 1
493
495
  branches, softs = branches[:n], softs[:n]
494
- if kind == 'and':
496
+ if kind == 'and' and not whole:
495
497
  cuts = [False] * len(branches)
496
498
  return tuple(branches), tuple(cuts), tuple(softs)
497
499
 
@@ -1054,8 +1056,11 @@ class _Write(Hooks):
1054
1056
  def recursive(self, op, t, rest, nop, unwrapped):
1055
1057
  raise TranslationError('** in a write not supported yet')
1056
1058
 
1059
+ def and_group(self, op, *args):
1060
+ return self.group(op, 'and', *_branches(op, 'and', whole=True), *args)
1061
+
1057
1062
  def group(self, op, kind, branches, cuts, softs, t, rest, nop, unwrapped):
1058
- raise TranslationError('a group in a write not supported yet')
1063
+ return t._write_group(kind, branches, cuts, softs, rest, nop, unwrapped)
1059
1064
 
1060
1065
  def not_group(self, op, t, rest, nop, unwrapped):
1061
1066
  raise TranslationError('a negation in a write not supported yet')
@@ -1632,6 +1637,50 @@ class Translator:
1632
1637
  return self._w_each(kind, value, first, test, child, null)
1633
1638
  return self._w_key(kind, value, child, absent, null)
1634
1639
 
1640
+ def _write_group(self, kind, branches, cuts, softs, rest, nop, unwrapped):
1641
+ """
1642
+ The writer of a group at a node, `rest` the ops after it, as
1643
+ dotted's update writes one. A disjunction writes each branch
1644
+ where it matches, the rest after it, on the node as the branches
1645
+ before it left it, a branch with an append slot always, and ends
1646
+ after a branch a cut follows that matched; where none matched,
1647
+ the last concrete branch is written, built as it lacks. A
1648
+ conjunction writes every branch, in turn, where each matches on
1649
+ the node as it was or is a plain path it can build, up to the
1650
+ first a cut follows that matched; else nothing. A first match
1651
+ writes the first branch that appends or, alone, matches; else
1652
+ the last concrete branch.
1653
+ """
1654
+ if any(softs):
1655
+ raise TranslationError('a soft cut in a write not supported yet')
1656
+ pass_nop = nop and not unwrapped
1657
+ parts = []
1658
+ for branch, cut in zip(branches, cuts):
1659
+ way = tuple(branch) + tuple(rest)
1660
+ if not way:
1661
+ continue
1662
+ parts.append((tuple(branch), way, cut))
1663
+ if kind == 'first':
1664
+ cands = [(True if _groups.appends(branch) else self._w_matches(branch),
1665
+ self._write(way, pass_nop)) for branch, way, _ in parts]
1666
+ return self._w_first(cands, self._w_fallback(parts, pass_nop))
1667
+ if kind == 'and':
1668
+ return self._w_and([(self._w_matches(way), _groups._creatable(list(way)), cut,
1669
+ self._write(way, nop)) for _, way, cut in parts])
1670
+ ors = [(True if _groups.appends(branch) else self._w_matches(way), cut,
1671
+ self._write(way, nop)) for branch, way, cut in parts]
1672
+ return self._w_or(ors, self._w_fallback(parts, nop))
1673
+
1674
+ def _w_fallback(self, parts, nop):
1675
+ """
1676
+ The writer of the last concrete branch, as a disjunction writes
1677
+ where none of its branches matched; None where none is concrete.
1678
+ """
1679
+ for _, way, _ in reversed(parts):
1680
+ if _groups._is_concrete_path(list(way)):
1681
+ return self._write(way, nop)
1682
+ return None
1683
+
1635
1684
  def _write_append(self, op, rest, nop, unwrapped):
1636
1685
  """
1637
1686
  The writer of an append slot, `[+]` (`[+?]` where the node