On this page

Typed melding๏ƒ

๐ŸŸข Beginner ยท Lesson 16

Type hints and melding are friends - annotate what you meld and your editor (and your agent) knows every attribute from there on. melder ships py.typed, so checkers see real types, not Any.

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

Download this collection ยท Source on GitHub

Public surface๏ƒ

meld with annotations, the typed root namespace

Code๏ƒ

 1"""
 2TIER: beginner (16)
 3GOAL: Type hints and melding are friends - annotate what you meld and
 4      your editor (and your agent) knows every attribute from there on.
 5      melder ships py.typed, so checkers see real types, not Any.
 6SURFACE EXERCISED: meld with annotations, the typed root namespace
 7"""
 8import melder as md
 9
10
11class WeatherService:
12    def today(self) -> str:
13        return "sunny, 24C"
14
15
16def main() -> None:
17    book: md.Spellbook = md.Spellbook()
18    book.bind(spell=WeatherService, existence="unique")
19    conduit: md.Conduit = book.conjure()
20
21    # The string selects the spell; the annotation describes the returned object.
22    weather: WeatherService = conduit.meld("WeatherService")
23    report: str = weather.today()
24    assert report == "sunny, 24C"
25    print("typed end to end:", report)
26    print("hint: annotate melds - autocomplete does the remembering for you")
27
28
29if __name__ == "__main__":
30    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