code: def assert_matches_type(
      type_: Any,
      value: object,
      *,
      path: list[str],
      allow_none: bool = False,
  ) -> None:
      if allow_none and value is None:
          return
  
      if type_ is None or type_ is NoneType:
          assert value is None
          return
  
      origin = get_origin(type_) or type_
  
      if is_list_type(type_):
          return _assert_list_type(type_, value)
  
      if origin == str:
          assert isinstance(value, str)
      elif origin == int:
          assert isinstance(value, int)
      elif origin == bool:
          assert isinstance(value, bool)
      elif origin == float:
          assert isinstance(value, float)
      elif origin == bytes:
          assert isinstance(value, bytes)
      elif origin == datetime:
          assert isinstance(value, datetime)
      elif origin == date:
          assert isinstance(value, date)
      elif origin == object:
          # nothing to do here, the expected type is unknown
          pass
      elif origin == Literal:
          assert value in get_args(type_)
      elif origin == dict:
          assert is_dict(value)
  
          args = get_args(type_)
          key_type = args[0]
          items_type = args[1]
  
          for key, item in value.items():
              assert_matches_type(
                  key_type, key, path=[*path, "<dict key>"]
              )
              assert_matches_type(
                  items_type, item, path=[*path, "<dict item>"]
              )
      elif is_union_type(type_):
          for i, variant in enumerate(get_args(type_)):
              try:
                  assert_matches_type(
                      variant, value, path=[*path, f"variant {i}"]
                  )
                  return
              except AssertionError:
                  traceback.print_exc()
                  continue
  
          raise AssertionError("Did not match any variants")
      elif issubclass(origin, BaseModel):
          assert isinstance(value, type_)
          assert assert_matches_model(
              type_, cast(Any, value), path=path
          )
      elif (
          inspect.isclass(origin)
          and origin.__name__ == "HttpxBinaryResponseContent"
      ):
          assert (
              value.__class__.__name__ == "HttpxBinaryResponseContent"
          )
      else:
          assert None, f"Unhandled field type: {type_}"
  
file_path: openai-python/tests/utils.py
imports: from __future__ import annotations
  import os
  import inspect
  import traceback
  import contextlib
  from typing import Any, TypeVar, Iterator, cast
  from datetime import date, datetime
  from typing_extensions import Literal, get_args, get_origin, assert_type
  from openai._types import NoneType
  from openai._utils import is_dict, is_list, is_list_type, is_union_type
  from openai._compat import PYDANTIC_V2, field_outer_type, get_model_fields
  from openai._models import BaseModel
label_desc: Use image node_id 2 for calling a global function with example usage: assert_matches_type(type_, value) and returns: _assert_list_type