On this page

Scopes that nest๏ƒ

Beginner. Child scopes, no configuration.

import melder as md


class Config:
    """Shared configuration for this example."""


class Session:
    """State scoped to one conduit."""


book = md.Spellbook()
book.bind(spell=Config, existence="unique")
book.bind(spell=Session, existence="unique_per_conduit")

with book.conjure() as root:
    with root.enter_lesser_conduit() as child:
        assert root.meld("Config") is child.meld("Config")       # shared
        assert root.meld("Session") is not child.meld("Session") # per-scope

Expected outcome: both assertions pass, with no printed output. The child scope ends first, then the root; a child does not create another book or another root.

Runnable examples๏ƒ

All beginner examples ยท Level contents ยท Full contents

Canonical page source