code: def _maybe_cast_to_extension_array(
      cls: type[ExtensionArray],
      obj: ArrayLike,
      dtype: ExtensionDtype | None = None,
  ) -> ArrayLike:
      """
      Call to `_from_sequence` that returns the object unchanged on Exception.
  
      Parameters
      ----------
      cls : class, subclass of ExtensionArray
      obj : arraylike
          Values to pass to cls._from_sequence
      dtype : ExtensionDtype, optional
  
      Returns
      -------
      ExtensionArray or obj
      """
      result: ArrayLike
  
      if dtype is not None:
          try:
              result = cls._from_scalars(obj, dtype=dtype)
          except (TypeError, ValueError):
              return obj
          return result
  
      try:
          result = cls._from_sequence(obj, dtype=dtype)
      except Exception:
          # We can't predict what downstream EA constructors may raise
          result = obj
      return result
  
imports: from __future__ import annotations
  import datetime
  import functools
  from typing import TYPE_CHECKING, Any, Literal, TypeVar, cast, overload
  import warnings
  import numpy
  from pandas._config import using_pyarrow_string_dtype
  from pandas._libs import Interval, Period, lib
  from pandas._libs.missing import NA, NAType, checknull
  from pandas._libs.tslibs import NaT, OutOfBoundsDatetime, OutOfBoundsTimedelta, Timedelta, Timestamp, is_supported_dtype
  from pandas._libs.tslibs.timedeltas import array_to_timedelta64
  from pandas.compat.numpy import np_version_gt2
  from pandas.errors import IntCastingNaNError, LossySetitemError
  from pandas.core.dtypes.common import ensure_int8, ensure_int16, ensure_int32, ensure_int64, ensure_object, ensure_str, is_bool, is_complex, is_float, is_integer, is_object_dtype, is_scalar, is_string_dtype, pandas_dtype
  from pandas.core.dtypes.dtypes import ArrowDtype, BaseMaskedDtype, CategoricalDtype, DatetimeTZDtype, ExtensionDtype, IntervalDtype, PandasExtensionDtype, PeriodDtype
  from pandas.core.dtypes.generic import ABCExtensionArray, ABCIndex, ABCSeries
  from pandas.core.dtypes.inference import is_list_like
  from pandas.core.dtypes.missing import is_valid_na_for_dtype, isna, na_value_for_dtype, notna
  from pandas.io._util import _arrow_dtype_mapping
label_desc: Use image node_id 15 for calling a global function with example usage: _maybe_cast_to_extension_array(cls, obj, dtype) and returns: result, result, obj