code: def extract_type_var_from_base(
      typ: type, *, generic_bases: tuple[type, ...], index: int
  ) -> type:
      """Given a type like `Foo[T]`, returns the generic type variable `T`.
  
      This also handles the case where a concrete subclass is given, e.g.
      ```py
      class MyResponse(Foo[bytes]):
          ...
  
      extract_type_var(MyResponse, bases=(Foo,), index=0) -> bytes
      ```
      """
      cls = cast(object, get_origin(typ) or typ)
      if cls in generic_bases:
          # we're given the class directly
          return extract_type_arg(typ, index)
  
      # if a subclass is given
      # ---
      # this is needed as __orig_bases__ is not present in the typeshed stubs
      # because it is intended to be for internal use only, however there does
      # not seem to be a way to resolve generic TypeVars for inherited subclasses
      # without using it.
      if isinstance(cls, InheritsGeneric):
          target_base_class: Any | None = None
          for base in cls.__orig_bases__:
              if base.__origin__ in generic_bases:
                  target_base_class = base
                  break
  
          if target_base_class is None:
              raise RuntimeError(
                  "Could not find the generic base class;\n"
                  "This should never happen;\n"
                  f"Does {cls} inherit from one of {generic_bases} ?"
              )
  
          return extract_type_arg(target_base_class, index)
  
      raise RuntimeError(
          f"Could not resolve inner type variable at index {index} for {typ}"
      )
  
file_path: openai-python/src/openai/_utils/_typing.py
imports: from __future__ import annotations
  from typing import Any, cast
  from typing_extensions import Required, Annotated, get_args, get_origin
  from .._types import InheritsGeneric
  from .._compat import is_union
label_desc: Use image node_id 7 for calling a global function with example usage: extract_type_var_from_base(typ) and returns: extract_type_arg, extract_type_arg