On this page

Spell override construction๏ƒ

๐ŸŸก Intermediate ยท Lesson 08

Two honest ways to construct with configuration: a factory that closes over its config (bind-site), and override at meld - a FLAT dict of keyword overrides for the melded spell's OWN constructor. Simple and top-level on purpose; targeting objects DEEPER in the graph is an advanced-tier lesson. (bind(**kwargs) is a different channel entirely: it lands on spell.metadata - lesson 06.)

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

Download this collection ยท Source on GitHub

Public surface๏ƒ

factory spells, meld(override={...})

Code๏ƒ

 1"""
 2TIER: intermediate (08)
 3GOAL: Two honest ways to construct with configuration: a factory that
 4      closes over its config (bind-site), and override at meld -
 5      a FLAT dict of keyword overrides for the melded spell's OWN
 6      constructor. Simple and top-level on purpose; targeting objects
 7      DEEPER in the graph is an advanced-tier lesson.
 8      (bind(**kwargs) is a different channel entirely: it lands on
 9      spell.metadata - lesson 06.)
10SURFACE EXERCISED: factory spells, meld(override={...})
11"""
12import melder as md
13
14
15class SmtpMailer:
16    def __init__(self, host: str = "localhost", port: int = 25) -> None:
17        self.host = host
18        self.port = port
19
20
21def production_mailer() -> SmtpMailer:
22    return SmtpMailer(host="smtp.example.com", port=2525)
23
24
25def main() -> None:
26    book = md.Spellbook()
27    book.bind(spell=production_mailer, existence="unique",
28              spellframe="mail", binding_name="mailer")
29    book.bind(spell=SmtpMailer, existence="many",
30              spellframe="mail", binding_name="raw-mailer")
31    conduit = book.conjure()
32
33    mailer = conduit.meld(spellframe="mail", binding_name="mailer")
34    assert (mailer.host, mailer.port) == ("smtp.example.com", 2525)
35    print("factory-configured:", mailer.host, mailer.port)
36
37    overridden = conduit.meld(
38        spellframe="mail", binding_name="raw-mailer",
39        override={"host": "smtp.test.local", "port": 1025},
40    )
41    assert (overridden.host, overridden.port) == ("smtp.test.local", 1025)
42    print("meld-site override:", overridden.host, overridden.port)
43
44
45if __name__ == "__main__":
46    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