On this page

Target a dependency inside the graph๏ƒ

Prerequisite: flat overrides. The key in the override mapping expresses how to find a constructor socket below the melded root.

Form

Example

Match rule

Exact path

transport>credentials

The named socket path

Unique wildcard

*credentials

Exactly one matching socket

Broadcast

**credentials

At least one matching socket; apply to all matches

The wildcard lesson exercises one match, multiple matches, no matches, and overlap. When a broadcast and exact path name the same socket, the exact path takes precedence. The complete example keeps its objects many so later melds construct clean graphs.

Targeting and lifetime are separate decisions๏ƒ

The deep-path lesson deliberately uses unique. Its override helps construct a singleton transport, and a later plain meld retrieves that same transport with the injected credentials still inside it. The substitution lasts as long as the object it helped create. It is not automatically limited to the duration of a call.

Run both examples: the first demonstrates this lifetime consequence; the second demonstrates the match grammar and fresh-instance contrast.

The workflow in code๏ƒ

These are the core steps from the saved example. Use its complete linked script for all class definitions and setup.

 1def main() -> None:
 2    conduit = _book().conjure(name="override-root")
 3
 4    fixture = Credentials()
 5    fixture.source = "test-fixture"
 6
 7    # UNIQUE - *param. MailPipeline has exactly ONE credentials socket
 8    # under it, so the wildcard resolves without naming the path.
 9    mail = conduit.meld(
10        "MailPipeline",
11        override={"*credentials": fixture},
12    )
13    assert mail.transport.credentials is fixture
14    print("*credentials found the single socket:",
15          mail.transport.credentials.source)
16
17    # ...and the same spec against a root with TWO matching sockets is
18    # REFUSED. "exactly one" is a requirement, not a preference - this is
19    # the whole reason the form is safe to reach for.
20    try:
21        conduit.meld(
22            "BackupPipeline",
23            override={"*credentials": fixture},
24        )
25        raise AssertionError("expected a refusal - *param matched twice")
26    except Exception as error:
27        print("*credentials refused two matches:", type(error).__name__)
28
29    # BROADCAST - **param. Same graph, and now hitting every match is
30    # exactly what was asked for.
31    backup = conduit.meld(
32        "BackupPipeline",
33        override={"**credentials": fixture},
34    )
35    assert backup.transport.credentials is fixture
36    assert backup.archive.credentials is fixture
37    print("**credentials hit both sockets:",
38          backup.transport.credentials.source,
39          "/", backup.archive.credentials.source)
40
41    # A broadcast that matches NOTHING is refused too - "at least one" is
42    # also enforced. A no-op override is a caller mistake, not a default.
43    try:
44        conduit.meld(
45            "MailPipeline",
46            override={"**nosuchparam": fixture},
47        )
48        raise AssertionError("expected a refusal - **param matched nothing")
49    except Exception as error:
50        print("**nosuchparam refused zero matches:", type(error).__name__)
51
52    # PRECEDENCE. Broadcast everything, then name one socket exactly - the
53    # exact path is MORE SPECIFIC and wins where the two overlap.
54    specific = Credentials()
55    specific.source = "archive-only"
56    mixed = conduit.meld(
57        "BackupPipeline",
58        override={
59            "**credentials": fixture,
60            "archive>credentials": specific,
61        },
62    )
63    assert mixed.transport.credentials is fixture
64    assert mixed.archive.credentials is specific
65    print("overlap resolved by specificity - transport:",
66          mixed.transport.credentials.source,
67          "| archive:", mixed.archive.credentials.source)
68
69    # `many` kept the blast radius inside the call: a plain meld gets a
70    # clean graph with no fixture in it.
71    clean = conduit.meld("BackupPipeline")
72    assert clean.transport.credentials is not fixture
73    assert clean.archive.credentials.source == "vault"
74    print("plain meld is untouched:", clean.archive.credentials.source)
75
76    print()
77    print("three forms: exact path, *one, **all - the grammar is in the key")
78    print("match counts are ENFORCED - a guessing wildcard would fail silently")

Runnable examples๏ƒ

All advanced examples ยท Level contents ยท Full contents

Canonical page source