MCPcopy
hub / github.com/marimo-team/marimo / update

Method update

marimo/_save/cache.py:310–364  ·  view source on GitHub ↗

Loads values from scope, updating the cache.

(
        self,
        scope: dict[str, Any],
        meta: dict[MetaKey, Any] | None = None,
        preserve_pointers: bool = True,
    )

Source from the content-addressed store, hash-verified

308 return result
309
310 def update(
311 self,
312 scope: dict[str, Any],
313 meta: dict[MetaKey, Any] | None = None,
314 preserve_pointers: bool = True,
315 ) -> None:
316 """Loads values from scope, updating the cache."""
317 for var, lookup in self.contextual_defs():
318 if lookup not in scope:
319 raise CacheException(
320 "Failure while saving cached values. "
321 "Cache expected a reference to a "
322 f"variable that is not present ({lookup})."
323 )
324 self.defs[var] = scope[lookup]
325
326 self.meta = {}
327 if meta is not None:
328 for metakey, metavalue in meta.items():
329 if metakey not in get_args(MetaKey):
330 raise CacheException(f"Unexpected meta key: {metakey}")
331 self.meta[metakey] = metavalue
332 self.meta["version"] = MARIMO_CACHE_VERSION
333
334 defs = {**globals(), **scope}
335 for ref in self.stateful_refs:
336 if ref not in defs:
337 raise CacheException(
338 "Failure while saving cached values. "
339 "Cache expected a reference to a "
340 f"variable that is not present ({ref})."
341 )
342 value = defs[ref]
343 if isinstance(value, SetFunctor):
344 self.defs[ref] = value._state()
345 elif isinstance(value, UIElement):
346 self.defs[ref] = value.value
347 else:
348 raise CacheException(
349 "Failure while saving cached values. "
350 "Unexpected stateful reference type "
351 f"({type(value)}:{ref})."
352 )
353
354 # Convert objects to stubs in both defs and meta
355 memo: dict[int, Any] = {} # Track processed objects to handle cycles
356 for key, value in self.defs.items():
357 self.defs[key] = self._convert_to_stub_if_needed(
358 value, memo, preserve_pointers
359 )
360
361 for key, value in self.meta.items():
362 self.meta[key] = self._convert_to_stub_if_needed(
363 value, memo, preserve_pointers
364 )
365
366 def _convert_to_stub_if_needed(
367 self,

Calls 4

contextual_defsMethod · 0.95
CacheExceptionClass · 0.85
itemsMethod · 0.45