On this page

Spellmap defaults๏ƒ

๐ŸŸก Intermediate ยท Lesson 16

SpellMap - the declarative DI placeholder. As a constructor DEFAULT it declares exactly which spell fills the parameter, including frame + binding_name targeting. Exactly-one law: ambiguous or missing targets fail at conjure, not at runtime.

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/16_spellmap_defaults.py
py -3.14t UX_and_AIX_experiences/02_intermediate/16_spellmap_defaults.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

md.SpellMap as a constructor default

Code๏ƒ

 1"""
 2TIER: intermediate (16)
 3GOAL: SpellMap - the declarative DI placeholder. As a constructor
 4      DEFAULT it declares exactly which spell fills the parameter,
 5      including frame + binding_name targeting. Exactly-one law:
 6      ambiguous or missing targets fail at conjure, not at runtime.
 7SURFACE EXERCISED: md.SpellMap as a constructor default
 8"""
 9import melder as md
10
11
12class PrimaryStore:
13    label = "primary"
14
15
16class Consumer:
17    def __init__(self, store=md.SpellMap(PrimaryStore)) -> None:
18        self.store = store
19
20
21def main() -> None:
22    book = md.Spellbook()
23    book.bind(spell=PrimaryStore, existence="unique")
24    book.bind(spell=Consumer, existence="unique")
25    conduit = book.conjure()
26
27    consumer = conduit.meld(spell=Consumer)
28    assert isinstance(consumer.store, PrimaryStore)
29    print("SpellMap default resolved:", consumer.store.label)
30
31
32if __name__ == "__main__":
33    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

API contracts๏ƒ