Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Fix spurious "truth value of UIElement" warning for anywidgets (#8148)

Trevor Manzbd53833bcf5c
diff --git a/marimo/_plugins/ui/_impl/from_anywidget.py b/marimo/_plugins/ui/_impl/from_anywidget.py
index eeba99203a..bcea6529ac 100644
--- a/marimo/_plugins/ui/_impl/from_anywidget.py
+++ b/marimo/_plugins/ui/_impl/from_anywidget.py
@@ -80,7 +80,8 @@ _cache: WeakCache[AnyWidget, UIElement[Any, Any]] = WeakCache() # type: ignore[
def from_anywidget(widget: AnyWidget) -> UIElement[Any, Any]:
"""Create a UIElement from an AnyWidget."""
- if not (el := _cache.get(widget)):
+ el = _cache.get(widget)
+ if el is None:
el = anywidget(widget)
_cache.add(widget, el) # type: ignore[no-untyped-call, unused-ignore, assignment] # noqa: E501
return el