On this page

Defaults just work๏ƒ

๐ŸŸข Beginner ยท Lesson 20

Your constructor defaults ARE the configuration - a class with default arguments melds without any extra setup. melder calls YOUR init; Python fills the defaults.

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

Download this collection ยท Source on GitHub

Public surface๏ƒ

plain constructor defaults through meld

Code๏ƒ

 1"""
 2TIER: beginner (20)
 3GOAL: Your constructor defaults ARE the configuration - a class with
 4      default arguments melds without any extra setup. melder calls
 5      YOUR __init__; Python fills the defaults.
 6SURFACE EXERCISED: plain constructor defaults through meld
 7"""
 8import melder as md
 9
10
11class HttpClient:
12    def __init__(self, timeout: int = 30, retries: int = 3) -> None:
13        self.timeout = timeout
14        self.retries = retries
15
16
17def main() -> None:
18    book = md.Spellbook()
19    book.bind(spell=HttpClient, existence="unique")
20    conduit = book.conjure()
21
22    client = conduit.meld(spell=HttpClient)
23    assert (client.timeout, client.retries) == (30, 3)
24    print("defaults arrived untouched:", client.timeout, client.retries)
25
26
27if __name__ == "__main__":
28    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