On this page
Double bind outcome๏
๐ข Beginner ยท Lesson 30
Binding the SAME class twice is refused - a spell_id is the SHA256 of the class's code, and one object registers once, under any binding name or lifecycle. When one shape must serve two roles, make two shapes: subclass it (see 24).
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/30_double_bind_outcome.py
py -3.14t UX_and_AIX_experiences/01_beginner/30_double_bind_outcome.py
Public surface๏
the one-object law at bind time
Code๏
1"""
2TIER: beginner (30)
3GOAL: Binding the SAME class twice is refused - a spell_id is the
4 SHA256 of the class's code, and one object registers once, under
5 any binding name or lifecycle. When one shape must serve two
6 roles, make two shapes: subclass it (see 24).
7SURFACE EXERCISED: the one-object law at bind time
8"""
9import melder as md
10
11
12class Doubled:
13 pass
14
15
16class DoubledAgain(Doubled):
17 pass
18
19
20def main() -> None:
21 book = md.Spellbook()
22 book.bind(spell=Doubled, existence="unique")
23 try:
24 book.bind(spell=Doubled, existence="many")
25 print("second bind unexpectedly accepted")
26 except Exception as err:
27 print("same object refused:", type(err).__name__)
28
29 # the fix: a subclass IS a new class - a new spell_id (and a new name)
30 book.bind(spell=DoubledAgain, existence="many")
31 print("subclass bound cleanly - two shapes, two spells")
32
33
34if __name__ == "__main__":
35 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.