code: def asarray_tuplesafe(
      values: Iterable, dtype: NpDtype | None = None
  ) -> ArrayLike:
      if not (
          isinstance(values, (list, tuple))
          or hasattr(values, "__array__")
      ):
          values = list(values)
      elif isinstance(values, ABCIndex):
          return values._values
  
      if isinstance(values, list) and dtype in [np.object_, object]:
          return construct_1d_object_array_from_listlike(values)
  
      try:
          with warnings.catch_warnings():
              # Can remove warning filter once NumPy 1.24 is min version
              if not np_version_gte1p24:
                  warnings.simplefilter(
                      "ignore", np.VisibleDeprecationWarning
                  )
              result = np.asarray(values, dtype=dtype)
      except ValueError:
          # Using try/except since it's more performant than checking is_list_like
          # over each element
          # error: Argument 1 to "construct_1d_object_array_from_listlike"
          # has incompatible type "Iterable[Any]"; expected "Sized"
          return construct_1d_object_array_from_listlike(values)  # type: ignore[arg-type]
  
      if issubclass(result.dtype.type, str):
          result = np.asarray(values, dtype=object)
  
      if result.ndim == 2:
          # Avoid building an array of arrays:
          values = [tuple(x) for x in values]
          result = construct_1d_object_array_from_listlike(values)
  
      return result
  
imports: from __future__ import annotations
  import builtins
  from collections import abc, defaultdict
  from collections.abc import Collection, Generator, Hashable, Iterable, Sequence
  import contextlib
  from functools import partial
  import inspect
  from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast, overload
  import warnings
  import numpy
  from pandas._libs import lib
  from pandas.compat.numpy import np_version_gte1p24
  from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
  from pandas.core.dtypes.common import is_bool_dtype, is_integer
  from pandas.core.dtypes.generic import ABCExtensionArray, ABCIndex, ABCMultiIndex, ABCSeries
  from pandas.core.dtypes.inference import iterable_not_string
label_desc: Use image node_id 13 for calling a global function with example usage: asarray_tuplesafe(values, dtype) and returns: result, construct_1d_object_array_from_listlike, values, construct_1d_object_array_from_listlike