On this page

Deep overrides paths through a graph๏ƒ

๐Ÿ”ต Expert ยท Lesson 10

OVERRIDES WHEN THE GRAPH IS DEEP. Advanced 19 taught the three TARGETING FORMS - path, *unique, **broadcast - on a shallow graph where the difference between them is mostly convenience. This is the same grammar at depth four, where it stops being convenience and starts being the only way to say what you mean.

A PATH IS A CHAIN OF SOCKET NAMES, NOT A TYPE "gateway>upstream>credentials" Each hop is the PARAMETER NAME on the class at that level. You are walking the constructor signatures, not the class hierarchy, and that distinction is the whole lesson: two sockets of the SAME type at different depths are different addresses.

WHAT DEPTH CHANGES

  1. AMBIGUITY BECOMES THE NORMAL CASE. On a two-node graph *credentials is exact because there is one. At depth four the same class appears on several branches, * starts refusing, and you either name the path or mean **.

  2. YOU CAN REPLACE A BRANCH, NOT JUST A LEAF. A path that stops half way swaps the whole subtree underneath it - everything that node would have built is replaced by the object you handed in. That is the difference between patching a value and grafting a different world in.

  3. PRECEDENCE STOPS BEING THEORETICAL. Give an exact path and a broadcast that both cover one socket and the EXACT PATH WINS. Specificity beats reach, which is the only rule that lets you say "all of them except this one" in a single call.

  4. A WRONG PATH REFUSES AND NAMES ITSELF. It does not silently apply to the nearest match and it does not no-op. At depth four a typo is otherwise invisible, so the refusal IS the feature.

THE HOUSE RULE UNDERNEATH ALL OF IT Every one of these is the never-substitute law again: melder would rather refuse than guess which socket you meant. Advanced 19 proved it on counts; this proves it on addresses.

Before you run๏ƒ

Use the Expert guide for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules.

Run the saved script๏ƒ

python UX_and_AIX_experiences/04_expert/10_deep_overrides_paths_through_a_graph.py
py -3.14t UX_and_AIX_experiences/04_expert/10_deep_overrides_paths_through_a_graph.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

conduit.meld(override=...) with multi-hop paths, branch replacement, path-beats-broadcast precedence, and the refusal on an unresolvable path

Code๏ƒ

  1"""
  2TIER: expert (10)
  3GOAL: OVERRIDES WHEN THE GRAPH IS DEEP. Advanced 19 taught the three
  4      TARGETING FORMS - path, *unique, **broadcast - on a shallow graph
  5      where the difference between them is mostly convenience. This is
  6      the same grammar at depth four, where it stops being convenience
  7      and starts being the only way to say what you mean.
  8
  9      A PATH IS A CHAIN OF SOCKET NAMES, NOT A TYPE
 10        "gateway>upstream>credentials"
 11      Each hop is the PARAMETER NAME on the class at that level. You are
 12      walking the constructor signatures, not the class hierarchy, and
 13      that distinction is the whole lesson: two sockets of the SAME type
 14      at different depths are different addresses.
 15
 16      WHAT DEPTH CHANGES
 17
 18      1. AMBIGUITY BECOMES THE NORMAL CASE. On a two-node graph
 19         `*credentials` is exact because there is one. At depth four the
 20         same class appears on several branches, `*` starts refusing, and
 21         you either name the path or mean `**`.
 22
 23      2. YOU CAN REPLACE A BRANCH, NOT JUST A LEAF. A path that stops
 24         half way swaps the whole subtree underneath it - everything that
 25         node would have built is replaced by the object you handed in.
 26         That is the difference between patching a value and grafting a
 27         different world in.
 28
 29      3. PRECEDENCE STOPS BEING THEORETICAL. Give an exact path and a
 30         broadcast that both cover one socket and the EXACT PATH WINS.
 31         Specificity beats reach, which is the only rule that lets you
 32         say "all of them except this one" in a single call.
 33
 34      4. A WRONG PATH REFUSES AND NAMES ITSELF. It does not silently
 35         apply to the nearest match and it does not no-op. At depth four
 36         a typo is otherwise invisible, so the refusal IS the feature.
 37
 38      THE HOUSE RULE UNDERNEATH ALL OF IT
 39      Every one of these is the never-substitute law again: melder would
 40      rather refuse than guess which socket you meant. Advanced 19 proved
 41      it on counts; this proves it on addresses.
 42SURFACE EXERCISED: conduit.meld(override=...) with multi-hop paths,
 43                   branch replacement, path-beats-broadcast precedence,
 44                   and the refusal on an unresolvable path
 45VERIFY: RUN GREEN 2026-08-03 on the owner's 3.14t harness.
 46"""
 47import melder as md
 48
 49
 50# A four-level graph. Note the SOCKET NAMES - those are what a path walks.
 51class Credentials:
 52    def __init__(self) -> None:
 53        self.label = "real"
 54
 55
 56class Upstream:
 57    def __init__(self, credentials: Credentials) -> None:
 58        self.credentials = credentials
 59
 60
 61class Gateway:
 62    def __init__(self, upstream: Upstream) -> None:
 63        self.upstream = upstream
 64
 65
 66class Mirror:
 67    def __init__(self, upstream: Upstream) -> None:
 68        self.upstream = upstream
 69
 70
 71class Edge:
 72    def __init__(self, gateway: Gateway, mirror: Mirror) -> None:
 73        self.gateway = gateway
 74        self.mirror = mirror
 75
 76
 77def main() -> None:
 78    book = md.Spellbook(aetheric_frame="deep-overrides")
 79    for spell in (Credentials, Upstream, Gateway, Mirror, Edge):
 80        book.bind(spell=spell, existence="many")
 81    conduit = book.conjure(name="deep-root")
 82
 83    # The shape, unmodified. TWO credentials sockets exist - one under
 84    # gateway, one under mirror - and they are four hops down.
 85    plain = conduit.meld("Edge")
 86    assert plain.gateway.upstream.credentials.label == "real"
 87    assert plain.mirror.upstream.credentials.label == "real"
 88    print("graph built: two credentials sockets, both at depth 4")
 89
 90    # 1. A PATH IS A CHAIN OF SOCKET NAMES. Every hop is a parameter name
 91    #    on the class at that level.
 92    swapped = Credentials()
 93    swapped.label = "gateway-only"
 94    one = conduit.meld(
 95        "Edge",
 96        override={"gateway>upstream>credentials": swapped},
 97    )
 98    assert one.gateway.upstream.credentials.label == "gateway-only"
 99    assert one.mirror.upstream.credentials.label == "real"
100    print()
101    print("path hit ONE socket; its twin on the other branch was untouched")
102
103    # 2. STOP THE PATH EARLY AND YOU REPLACE A BRANCH. Everything the
104    #    node would have built below it is replaced too.
105    grafted_credentials = Credentials()
106    grafted_credentials.label = "grafted"
107    grafted = conduit.meld(
108        "Edge",
109        override={"mirror>upstream": Upstream(grafted_credentials)},
110    )
111    assert grafted.mirror.upstream.credentials.label == "grafted"
112    assert grafted.gateway.upstream.credentials.label == "real"
113    print("a short path grafted a whole SUBTREE, not a leaf")
114
115    # 3. AMBIGUITY IS THE NORMAL CASE AT DEPTH. `*credentials` matches
116    #    twice here, and melder refuses rather than picking one.
117    try:
118        conduit.meld("Edge", override={"*credentials": swapped})
119        raise AssertionError("expected a refusal: *param matched twice")
120    except Exception as error:
121        print()
122        print("*credentials refused -", type(error).__name__)
123        print("  at depth, `there is exactly one` is usually false")
124
125    # ...and `**` is how you say you meant all of them.
126    everywhere = Credentials()
127    everywhere.label = "all"
128    broad = conduit.meld(
129        "Edge",
130        override={"**credentials": everywhere},
131    )
132    assert broad.gateway.upstream.credentials.label == "all"
133    assert broad.mirror.upstream.credentials.label == "all"
134    print("**credentials hit both")
135
136    # 4. PRECEDENCE: an exact path BEATS a broadcast that also covers it.
137    #    This is what lets one call say "all of them, except this one".
138    pinned = Credentials()
139    pinned.label = "pinned"
140    mixed = conduit.meld(
141        "Edge",
142        override={
143            "**credentials": everywhere,
144            "gateway>upstream>credentials": pinned,
145        },
146    )
147    assert mixed.gateway.upstream.credentials.label == "pinned"
148    assert mixed.mirror.upstream.credentials.label == "all"
149    print()
150    print("exact path beat the broadcast on the socket they shared:")
151    print("  gateway ->", mixed.gateway.upstream.credentials.label,
152          " mirror ->", mixed.mirror.upstream.credentials.label)
153
154    # 5. A WRONG PATH REFUSES AND SAYS SO. At depth four a typo is
155    #    otherwise undetectable - the refusal is the feature.
156    try:
157        conduit.meld(
158            "Edge",
159            override={"gateway>upstrem>credentials": swapped},
160        )
161        raise AssertionError("expected a refusal: no such path")
162    except Exception as error:
163        print()
164        print("typo'd path refused -", type(error).__name__)
165
166    print()
167    print("a path walks SOCKET NAMES, so identical types at different")
168    print("depths are different addresses")
169    print("specificity beats reach; melder refuses rather than guessing")
170
171
172if __name__ == "__main__":
173    main()

Check the outcome๏ƒ

The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here.

More expert examples ยท Level guide