code: def _ensure_int(x, name="unknown", must_be="an int", *, extra=""):
      """Ensure a variable is an integer."""
      # This is preferred over numbers.Integral, see:
      # https://github.com/scipy/scipy/pull/7351#issuecomment-299713159
      extra = f" {extra}" if extra else extra
      try:
          # someone passing True/False is much more likely to be an error than
          # intentional usage
          if isinstance(x, bool):
              raise TypeError()
          x = int(operator.index(x))
      except TypeError:
          raise TypeError(
              f"{name} must be {must_be}{extra}, got {type(x)}"
          )
      return x
  
imports: import numbers
  import operator
  import os
  import re
  from builtins import input
  from difflib import get_close_matches
  from importlib import import_module
  from pathlib import Path
  import numpy
  from ..defaults import HEAD_SIZE_DEFAULT, _handle_default
  from ..fixes import _compare_version, _median_complex
  from ._logging import _record_warnings, _verbose_safe_false, logger, verbose, warn
label_desc: Use image node_id 1 for calling a global function with example usage: _ensure_int(x, name, must_be) and returns: x