code: def _convert_to_numeric(item):
      
      if PY3:
          num_types = (int, float)
      else:                                 # pragma: no cover
          num_types = (int, long, float)    # noqa: F821
      # We don't wan't to perform any conversions if item is already a number
      if isinstance(item, num_types):
          return item
  
      # First try for an int conversion so that strings like "5" are converted
      # to 5 instead of 5.0 . This is safe as a direct int cast for a non integer
      # string raises a ValueError.
      try:
          num = int(to_unicode(item))
      except ValueError:
          try:
              num = float(to_unicode(item))
          except ValueError:
              return item
          else:
              return num
      except TypeError:
          return item
      else:
          return num
docs: Helper method to convert a string to float or int if possible.
  
      If the conversion is not possible, it simply returns the string.