code: def dtype_factory(kind, sizes, valid_sizes, endianness):
      # Utility function, shared logic for most integer and string types
      valid_endian = ("?", "<", "=", ">")
      check_argument(
          endianness in valid_endian,
          "Unknown endianness: was {}, must be in {}",
          endianness,
          valid_endian,
      )
      if valid_sizes is not None:
          if isinstance(sizes, int):
              sizes = (sizes,)
          check_argument(
              sizes, "Dtype must have at least one possible size."
          )
          check_argument(
              all(s in valid_sizes for s in sizes),
              "Invalid sizes: was {} must be an item or sequence in {}",
              sizes,
              valid_sizes,
          )
          if all(isinstance(s, int) for s in sizes):
              sizes = sorted({s // 8 for s in sizes})
      strat = st.sampled_from(sizes)
      if "{}" not in kind:
          kind += "{}"
      if endianness == "?":
          return strat.map(("<" + kind).format) | strat.map(
              (">" + kind).format
          )
      return strat.map((endianness + kind).format)
  
imports: import importlib
  import math
  from typing import TYPE_CHECKING, Any, Literal, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union
  import numpy
  from hypothesis import strategies
  from hypothesis._settings import note_deprecation
  from hypothesis.errors import HypothesisException, InvalidArgument
  from hypothesis.extra._array_helpers import NDIM_MAX, BasicIndex, BasicIndexStrategy, BroadcastableShapes, Shape, array_shapes, broadcastable_shapes, check_argument, check_valid_dims, mutually_broadcastable_shapes, order_check, valid_tuple_axes
  from hypothesis.internal.conjecture import utils
  from hypothesis.internal.coverage import check_function
  from hypothesis.internal.reflection import proxies
  from hypothesis.internal.validation import check_type
  from hypothesis.strategies._internal.numbers import Real
  from hypothesis.strategies._internal.strategies import Ex, T, check_strategy
  from hypothesis.strategies._internal.utils import defines_strategy
label_desc: Use image node_id 8 for calling a global function with example usage: dtype_factory(kind, sizes, valid_sizes, endianness) and returns: strat, unknown