On this page
Strings as vocabulary๏
๐ข Beginner ยท Lesson 07
The vocabulary enums all accept their string names too - config files and CLI flags can drive registration without importing the enums. Both spellings resolve to the same lifecycles.
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/07_strings_as_vocabulary.py
py -3.14t UX_and_AIX_experiences/01_beginner/07_strings_as_vocabulary.py
Public surface๏
md.Spellbook.bind, md.Spellbook.conjure, md.Existence.many, md.Conduit.meld
Code๏
1"""
2TIER: beginner (07)
3GOAL: The vocabulary enums all accept their string names too - config
4 files and CLI flags can drive registration without importing the
5 enums. Both spellings resolve to the same lifecycles.
6SURFACE EXERCISED: md.Spellbook.bind, md.Spellbook.conjure, md.Existence.many,
7 md.Conduit.meld
8"""
9import melder as md
10
11
12class FromStrings:
13 pass
14
15
16class FromEnums:
17 pass
18
19
20def main() -> None:
21 book = md.Spellbook()
22 book.bind(spell=FromStrings, existence="many")
23 book.bind(
24 spell=FromEnums,
25 existence=md.Existence.many,
26 )
27 conduit = book.conjure()
28
29 s_a, s_b = conduit.meld(spell=FromStrings), conduit.meld(spell=FromStrings)
30 e_a, e_b = conduit.meld(spell=FromEnums), conduit.meld(spell=FromEnums)
31 assert s_a is not s_b and e_a is not e_b
32 print("string and enum registrations behave identically (many)")
33
34
35if __name__ == "__main__":
36 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.