On this page
Scan bind decorator๏
๐ก Intermediate ยท Lesson 01
Declarative binding - tag classes where they live with @md.scan_bind, then register the whole module in one scan() call. The decorator stores intent only; nothing binds until scan time.
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/01_scan_bind_decorator.py
py -3.14t UX_and_AIX_experiences/02_intermediate/01_scan_bind_decorator.py
Public surface๏
md.scan_bind, md.Spellbook.scan, md.Existence, md.Permissions
Code๏
1"""
2TIER: intermediate (01)
3GOAL: Declarative binding - tag classes where they live with @md.scan_bind,
4 then register the whole module in one scan() call. The decorator
5 stores intent only; nothing binds until scan time.
6SURFACE EXERCISED: md.scan_bind, md.Spellbook.scan, md.Existence, md.Permissions
7"""
8import sys
9
10import melder as md
11
12
13@md.scan_bind(existence=md.Existence.unique, permissions=md.Permissions.create)
14class MetricsHub:
15 pass
16
17
18@md.scan_bind(existence=md.Existence.many, permissions=md.Permissions.create)
19class JobTicket:
20 pass
21
22
23def main() -> None:
24 book = md.Spellbook()
25 bound = book.scan(sys.modules[__name__])
26 print("scan bound", len(bound), "spells:", sorted(bound))
27 assert len(bound) == 2
28
29 conduit = book.conjure()
30 hub_a = conduit.meld(spell=MetricsHub)
31 hub_b = conduit.meld(spell=MetricsHub)
32 ticket_a = conduit.meld(spell=JobTicket)
33 ticket_b = conduit.meld(spell=JobTicket)
34 assert hub_a is hub_b and ticket_a is not ticket_b
35 print("decorated lifecycles held: unique hub, many tickets")
36
37
38if __name__ == "__main__":
39 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.