On this page

Lesser conduits child scopes๏ƒ

๐ŸŸก Intermediate ยท Lesson 07

Lesser conduits - lightweight CHILD SCOPES grown from a root with create_lesser_conduit(). A lesser conduit rides its root's world: it resolves the same spells without being a second root (one book still conjures ONE root). Lessers are unnamed by design; naming and upgrade_to_normal() belong to dynamic mode (lesson 21+). Teardown stays an explicit verb - cleanup() is yours to call.

Before you run๏ƒ

Use the Intermediate 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/02_intermediate/07_lesser_conduits_child_scopes.py
py -3.14t UX_and_AIX_experiences/02_intermediate/07_lesser_conduits_child_scopes.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

create_lesser_conduit, meld through a child scope, explicit cleanup()

Code๏ƒ

 1"""
 2TIER: intermediate (07)
 3GOAL: Lesser conduits - lightweight CHILD SCOPES grown from a root with
 4      create_lesser_conduit(). A lesser conduit rides its root's world:
 5      it resolves the same spells without being a second root (one book
 6      still conjures ONE root). Lessers are unnamed by design; naming
 7      and upgrade_to_normal() belong to dynamic mode (lesson 21+).
 8      Teardown stays an explicit verb - cleanup() is yours to call.
 9SURFACE EXERCISED: create_lesser_conduit, meld through a child scope,
10                   explicit cleanup()
11"""
12import melder as md
13
14
15class ScopedService:
16    pass
17
18
19def main() -> None:
20    book = md.Spellbook()
21    book.bind(spell=ScopedService, existence="unique")
22    root = book.conjure()
23
24    # A child scope: no second conjure, no second book - the family
25    # grows downward from the one root.
26    child = root.create_lesser_conduit()
27
28    # "unique" is a world singleton, so the child resolves the SAME
29    # instance the root does.
30    from_root = root.meld("ScopedService")
31    from_child = child.meld("ScopedService")
32    assert from_root is from_child
33    print("child scope melds the root's world:", type(from_child).__name__)
34
35    # Teardown is explicit and top-down: cleaning the root conduit tears
36    # its family down with it; the book guards further use.
37    root.cleanup()
38    book.cleanup()
39    try:
40        book.bind(spell=ScopedService, existence="unique")
41        print("post-cleanup bind unexpectedly succeeded")
42    except Exception as err:
43        print("post-cleanup bind guarded:", type(err).__name__)
44
45
46if __name__ == "__main__":
47    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 intermediate examples ยท Level guide