On this page

Explicit cleanup๏ƒ

๐ŸŸข Beginner ยท Lesson 10

Teardown is a verb you own - conduit.cleanup() then book.cleanup(), in that order, and a cleaned book refuses further work loudly. (Disposal hooks you registered fire during this walk - see 08/35.)

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

Download this collection ยท Source on GitHub

Public surface๏ƒ

cleanup verbs, post-cleanup guards

Code๏ƒ

 1"""
 2TIER: beginner (10)
 3GOAL: Teardown is a verb you own - conduit.cleanup() then book.cleanup(),
 4      in that order, and a cleaned book refuses further work loudly.
 5      (Disposal hooks you registered fire during this walk - see 08/35.)
 6SURFACE EXERCISED: cleanup verbs, post-cleanup guards
 7"""
 8import melder as md
 9
10
11class Service:
12    pass
13
14
15def main() -> None:
16    book = md.Spellbook()
17    book.bind(spell=Service, existence="unique")
18    conduit = book.conjure()
19    assert isinstance(conduit.meld("Service"), Service)
20
21    conduit.cleanup()
22    book.cleanup()
23    print("world torn down: conduit first, book second")
24
25    try:
26        book.bind(spell=Service, existence="unique")
27        print("post-cleanup bind unexpectedly succeeded")
28    except Exception as err:
29        print("cleaned book guards itself:", type(err).__name__)
30
31
32if __name__ == "__main__":
33    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