code: def deep_isinstance(obj, cls):
      """
      Enhanced version of :func:`isinstance` that can handle basic structured :mod:`typing` types,
      including Funsor terms and other :class:`~funsor.typing.GenericTypeMeta` instances,
      :class:`~typing.Union`, :class:`~typing.Tuple`, and :class:`~typing.FrozenSet`.
  
      Does not support :class:`~typing.TypeVar`, arbitrary :class:`~typing.Generic`,
      forward references, or mutable generic collection types like :class:`~typing.List`.
      Will attempt to fall back to :func:`isinstance` when it encounters
      an unsupported type in ``obj`` or ``cls``.
  
      Usage::
  
          x = (1, ("a", "b"))
          assert deep_isinstance(x, typing.Tuple[int, tuple])
          assert deep_isinstance(x, typing.Tuple[typing.Any, typing.Tuple[str, ...]])
  
      :param obj: An object that may be an instance of ``cls``.
      :param cls: A class that may be a parent class of ``obj``.
      """
  
      # compare to pytypes.is_of_type(obj, cls)
      try:
          return deep_issubclass(deep_type(obj), cls)
      except TypeError:
          return isinstance(obj, cls)
  
imports: import functools
  import sys
  import typing
  import weakref
  import typing_extensions
  from multipledispatch.variadic import Variadic
  from multipledispatch.variadic import isvariadic
label_desc: Use image node_id 10 for calling a global function with example usage: deep_isinstance(obj, cls) and returns: deep_issubclass, isinstance