On this page

Same class many names๏ƒ

๐ŸŸข Beginner ยท Lesson 24

One spell name, one visible spell - CURRENT RUNTIME TRUTH (probe- proven): conjure refuses ANY two spells sharing a name, even across frames, even with different internals. The working pattern for one shape in many roles: tiny subclasses, one name each. (The probe suite flags the intended SHA-content semantics as an open runtime question - the lesson here is what works TODAY.)

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/24_same_class_many_names.py
py -3.14t UX_and_AIX_experiences/01_beginner/24_same_class_many_names.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

subclass-per-role registration, mixed lifecycles

Code๏ƒ

 1"""
 2TIER: beginner (24)
 3GOAL: One spell name, one visible spell - CURRENT RUNTIME TRUTH (probe-
 4      proven): conjure refuses ANY two spells sharing a name, even
 5      across frames, even with different internals. The working pattern
 6      for one shape in many roles: tiny subclasses, one name each.
 7      (The probe suite flags the intended SHA-content semantics as an
 8      open runtime question - the lesson here is what works TODAY.)
 9SURFACE EXERCISED: subclass-per-role registration, mixed lifecycles
10"""
11import melder as md
12
13
14class Buffer:
15    pass
16
17
18class SharedBuffer(Buffer):
19    pass
20
21
22class ScratchBuffer(Buffer):
23    pass
24
25
26def main() -> None:
27    book = md.Spellbook()
28    book.bind(spell=SharedBuffer, existence="unique",
29              spellframe="pools", binding_name="shared")
30    book.bind(spell=ScratchBuffer, existence="many",
31              spellframe="pools", binding_name="scratch")
32    conduit = book.conjure()
33
34    shared_a = conduit.meld(spellframe="pools", binding_name="shared")
35    shared_b = conduit.meld(spellframe="pools", binding_name="shared")
36    scratch_a = conduit.meld(spellframe="pools", binding_name="scratch")
37    scratch_b = conduit.meld(spellframe="pools", binding_name="scratch")
38    assert shared_a is shared_b
39    assert scratch_a is not scratch_b
40    assert isinstance(shared_a, Buffer) and isinstance(scratch_a, Buffer)
41    print("one shape, two roles via subclasses: shared + scratch")
42
43
44if __name__ == "__main__":
45    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 beginner examples ยท Level guide