code: def _get_dtype_and_weakness(x):
      """Returns a TF type and weak type information from x.
  
      Args:
        x: an input scalar, array or a NumPy/TF/Python dtype.
  
      Raises:
        OverflowError: if Python int x is too large to convert to int32.
        NotImplementedError: when x is an unsupported input type.
  
      Returns:
        TF type and weak type information inferred from x in the form of
        (dtype, bool).
      """
      if isinstance(x, weak_tensor.WeakTensor):
          return (x.dtype, True)
      if isinstance(x, dtypes.DType):
          return (x, False)
      # TODO(b/286585200): Add support for `AutoCastVariable` in Keras.
      tf_dtype = getattr(x, "dtype", None)
      if isinstance(tf_dtype, dtypes.DType):
          return (tf_dtype, False)
      # `isinstance(tf_dtype, np.dtype)` handles classes that implement `dtype`
      # using `np.dtype` (e.g. `xla_extension.Array`).
      # This condition is put before e.g. python int/float because
      # `isinstance(np.float64(1), float)` returns True.
      if isinstance(x, (np.ndarray, np.generic)) or isinstance(
          tf_dtype, np.dtype
      ):
          # Use `dtypes.as_dtype(x.dtype)` because in `as_dtype`, the input will be
          # compared against a list of types including TF Dtypes which are protobufs.
          infer_dtype = dtypes.as_dtype(tf_dtype)
          return (infer_dtype, False)
      if isinstance(x, (bytes, str)) or tf_dtype in _all_str_dtypes:
          return _str
      try:
          if x in _NP_TO_TF:
              return (_NP_TO_TF[x], False)
      except TypeError:
          pass
      # bool type check must happen before int type check because
      # isinstance(True, int) == True (https://peps.python.org/pep-0285/).
      if isinstance(x, bool) or x == bool:
          return _b8
      # TODO(b/286585058): Update implementation depending on whether Python
      # scalars are inferred to 32 bit or 64 bit.
      if isinstance(x, _pi):
          if x < np.iinfo(np.int32).min or x > np.iinfo(np.int32).max:
              raise OverflowError(
                  f"Python int {x} too large to convert to np.int32"
              )
          return _i32w
      if x == int:
          return _i32w
      if isinstance(x, _pf) or x == float:
          return _f32w
      if isinstance(x, _pc) or x == complex:
          return _c128w
      if isinstance(x, tensor_shape.TensorShape):
          # Since TensorShape is always integer value, return int32.
          return _i32
      # Only support NumPy dtype objects with corresponding TF types.
      if isinstance(x, np.dtype):
          try:
              np_dtype = dtypes.as_dtype(x)
              return (np_dtype, False)
          except TypeError as exc:
              raise NotImplementedError(
                  f"Auto dtype conversion semantics does not support {x}. Try using a"
                  " NumPy built-in dtype objects or cast them explicitly."
              ) from exc
      raise NotImplementedError(
          f"Auto dtype conversion semantics does not support {type(x)} type."
      )
  
file_path: tensorflow-upstream/tensorflow/python/framework/flexible_dtypes.py
imports: import numpy
  from tensorflow.python.framework import composite_tensor
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import indexed_slices
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.framework import weak_tensor
  from tensorflow.python.ops import variables
  from tensorflow.python.util import nest
label_desc: Use image node_id 3 for calling a global function with example usage: _get_dtype_and_weakness(x) and returns: x,  True, x,  False, tf_dtype,  False, infer_dtype,  False, _str, _b8, _i32w, _i32w, _f32w, _c128w, _i32, _NP_TO_TF,  False, np_dtype,  False