class Dependabot::Uv::Version

def local_cmp_key

def local_cmp_key
  if local.nil?
    # Versions without a local segment should sort before those with one.
    NEGATIVE_INFINITY
  else
    # According to PEP440.
    # - Alphanumeric segments sort before numeric segments
    # - Alphanumeric segments sort lexicographically
    # - Numeric segments sort numerically
    # - Shorter versions sort before longer versions when the prefixes match exactly
    local&.map do |token|
      if token.is_a?(Integer)
        [token, ""]
      else
        [NEGATIVE_INFINITY, token]
      end
    end
  end
end