code: def visit_value_and_its_immediate_references(
      obj: Any, visitor: Callable[[Model], None]
  ) -> None:
      """Visit Models, HasProps, and Python containers.
  
      Recurses down HasProps references and Python containers (does not recurse
      down Model subclasses).
  
      The ordering in this function is to optimize performance.  We check the
      most comomn types (int, float, str) first so that we can quickly return in
      the common case.  We avoid isinstance and issubclass checks in a couple
      places with `type` checks because isinstance checks can be slow.
      """
      from .model import Model
  
      typ = type(obj)
      if typ in {
          int,
          float,
          str,
      }:  # short circuit on common scalar types
          return
      if typ is list or issubclass(
          typ, (list, tuple)
      ):  # check common containers
          for item in obj:
              visit_value_and_its_immediate_references(item, visitor)
      elif issubclass(typ, dict):
          for key, value in obj.items():
              visit_value_and_its_immediate_references(key, visitor)
              visit_value_and_its_immediate_references(value, visitor)
      elif issubclass(typ, HasProps):
          if issubclass(typ, Model):
              visitor(obj)
          else:
              # this isn't a Model, so recurse into it
              visit_immediate_value_references(obj, visitor)
      elif is_dataclass(obj):
          for _, value in entries(obj):
              visit_value_and_its_immediate_references(value, visitor)
  
file_path: bokeh/src/bokeh/model/util.py
imports: from __future__ import annotations
  import logging
  from typing import TYPE_CHECKING, Any, Callable
  from ..core.has_props import HasProps, Qualified
  from ..util.dataclasses import entries, is_dataclass
label_desc: Use image node_id 5 for calling a global function with example usage: visit_value_and_its_immediate_references(obj, visitor) without return types