Classes are the keys
A string namespace is quick to write; a class is the one your editor completes. Provide an instance and it registers under its own class, so the lookup below hands it back with the static type intact, under mypy and pyright alike.
-
use(Scope)is inferred asScope, notAny - An inner block overrides one tenant, the outer scope returns on exit
- A miss tries
set_default, thendefault=, then raises
@dataclass class Scope: db: Session tenant: str with provider(Scope(db=session, tenant="acme")): place_order(payload) def charge(total: int) -> None: scope = use(Scope) # -> Scope scope.db.bill(scope.tenant, total)