On this page
Meld a frame as dict๏
๐ข Beginner ยท Lesson 38
Closing the dict-style loop - a small helper melds a whole frame family into a plain {name: instance} dict, because the (frame, name) address space maps 1:1 onto the dicts users already think in.
Before you run๏
Use the Beginner 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/01_beginner/38_meld_a_frame_as_dict.py
py -3.14t UX_and_AIX_experiences/01_beginner/38_meld_a_frame_as_dict.py
Public surface๏
frame-family melding, dict-style consumption
Code๏
1"""
2TIER: beginner (38)
3GOAL: Closing the dict-style loop - a small helper melds a whole frame
4 family into a plain {name: instance} dict, because the (frame,
5 name) address space maps 1:1 onto the dicts users already think in.
6SURFACE EXERCISED: frame-family melding, dict-style consumption
7"""
8import melder as md
9
10
11class AuthMiddleware:
12 pass
13
14
15class LoggingMiddleware:
16 pass
17
18
19class RetryMiddleware:
20 pass
21
22
23MIDDLEWARE = {"auth": AuthMiddleware, "logging": LoggingMiddleware,
24 "retry": RetryMiddleware}
25
26
27def meld_frame(conduit: md.Conduit, frame: str, names: list[str]) -> dict:
28 return {name: conduit.meld(spellframe=frame, binding_name=name)
29 for name in names}
30
31
32def main() -> None:
33 book = md.Spellbook()
34 for name, cls in MIDDLEWARE.items():
35 book.bind(spell=cls, existence="unique",
36 spellframe="middleware", binding_name=name)
37 conduit = book.conjure()
38
39 stack = meld_frame(conduit, "middleware", list(MIDDLEWARE))
40 assert set(stack) == {"auth", "logging", "retry"}
41 assert all(v is not None for v in stack.values())
42 print("frame melded as dict:", {k: type(v).__name__ for k, v in stack.items()})
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.