On this page

Real objects no wrappers๏ƒ

๐ŸŸข Beginner ยท Lesson 28

Melded objects are YOUR objects - no proxies, no wrappers, no magic subclasses. What comes back IS the instance: identity checks hold, isinstance holds, and it works everywhere a plain object works. Many DI containers wrap; melder hands you the real thing.

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

Download this collection ยท Source on GitHub

Public surface๏ƒ

instance identity through meld

Code๏ƒ

 1"""
 2TIER: beginner (28)
 3GOAL: Melded objects are YOUR objects - no proxies, no wrappers, no
 4      magic subclasses. What comes back IS the instance: identity checks
 5      hold, isinstance holds, and it works everywhere a plain object
 6      works. Many DI containers wrap; melder hands you the real thing.
 7SURFACE EXERCISED: instance identity through meld
 8"""
 9import melder as md
10
11
12class Engine:
13    cylinders = 8
14
15
16def main() -> None:
17    book = md.Spellbook()
18    book.bind(spell=Engine, existence="unique")
19    conduit = book.conjure()
20
21    engine = conduit.meld(spell=Engine)
22    assert type(engine) is Engine
23    assert isinstance(engine, Engine) and engine.cylinders == 8
24    assert engine is conduit.meld(spell=Engine)
25    print("the real object, every time:", type(engine).__name__)
26
27
28if __name__ == "__main__":
29    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