code: def _find_widget_refs_by_state(widget, state):
      """Find references to other widgets in a widget's state"""
      # Copy keys to allow changes to state during iteration:
      keys = tuple(state.keys())
      for key in keys:
          value = getattr(widget, key)
          # Trivial case: Direct references to other widgets:
          if isinstance(value, Widget):
              yield value
          # Also check for buried references in known, JSON-able structures
          # Note: This might miss references buried in more esoteric structures
          elif isinstance(value, (list, tuple)):
              for item in value:
                  if isinstance(item, Widget):
                      yield item
          elif isinstance(value, dict):
              for item in value.values():
                  if isinstance(item, Widget):
                      yield item
  
file_path: catboost/contrib/python/ipywidgets/py3/ipywidgets/embed.py
imports: import json
  import re
  from .widgets import Widget, DOMWidget, widget
  from .widgets.widget_link import Link
  from .widgets.docutils import doc_subst
  from ._version import __html_manager_version__
label_desc: Use image node_id 1 for calling a global function with example usage: _find_widget_refs_by_state(widget, state) without return types