{"record":{"id":"74416cfce113d914","repo":"pypa/pip","slug":"python-version-must-contain-at-least-one-item","errorCode":null,"errorMessage":"python_version must contain at least one item","messagePattern":"python_version must contain at least one item","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/packaging/tags.py","lineNumber":600,"sourceCode":"    python_version: PythonVersion | None = None,\n) -> Iterator[Tag]:\n    \"\"\"\n    Yields the pure-Python tags compatible with ``python_version``.\n\n    The tags use the ``\"none\"`` ABI and ``\"any\"`` platform, so their\n    generation does not depend on the running platform.\n\n    .. versionadded:: 26.3\n\n    :param Sequence python_version: A one- or two-item sequence representing the\n                                 compatible version of Python. Defaults to\n                                 ``sys.version_info[:2]``.\n    :raises ValueError: If ``python_version`` is an empty sequence.\n    \"\"\"\n    if python_version is None:\n        python_version = sys.version_info[:2]\n    elif not python_version:\n        raise ValueError(\"python_version must contain at least one item\")\n    for version in _py_interpreter_range(python_version):\n        yield Tag(version, \"none\", \"any\")\n\n\ndef compatible_tags(\n    python_version: PythonVersion | None = None,\n    interpreter: str | None = None,\n    platforms: Iterable[str] | None = None,\n) -> Iterator[Tag]:\n    \"\"\"\n    Yields the tags for an interpreter compatible with the Python version\n    specified by ``python_version``.\n\n    The specific tags generated are:\n\n    - ``py*-none-<platform>``\n    - ``<interpreter>-none-any`` if ``interpreter`` is provided\n    - ``py*-none-any``","sourceCodeStart":582,"sourceCodeEnd":618,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/packaging/tags.py#L582-L618","documentation":"Raised as ValueError by pure_python_tags (tags.py:599-600) when python_version is an empty sequence (e.g. []). The function accepts None (defaults to sys.version_info[:2]) or a one/two-item version tuple, but an explicitly empty container is rejected because no interpreter tags can be generated from it.","triggerScenarios":"pure_python_tags([]); pure_python_tags(()) ; passing a list built from a filter that returned no elements (e.g. [v for v in versions if v > 99] yielding []).","commonSituations":"A version-detection helper that builds the python_version list dynamically and returns empty when no match is found; config that supplies an empty version range; conditional logic that clears the list before calling.","solutions":["Guard against empty: if not python_version: python_version = sys.version_info[:2] (or skip the call).","Default the parameter to None and let pure_python_tags use sys.version_info.","Validate the list is non-empty at the source before passing.","Catch ValueError and fall back to the current interpreter version."],"exampleFix":"# before\npure_python_tags([v for v in versions if v > 99])  # [] -> ValueError\n\n# after - default to current interpreter when empty\npv = [v for v in versions if v > 99] or None\npure_python_tags(pv)  # None -> uses sys.version_info[:2]","handlingStrategy":"validation","validationCode":"import sys\ndef safe_python_version(v):\n    return v or None  # let pure_python_tags use sys.version_info[:2]","typeGuard":"def is_nonempty_version(v) -> bool:\n    return v is None or (hasattr(v, '__len__') and len(v) >= 1)","tryCatchPattern":"try:\n    list(pure_python_tags(pv))\nexcept ValueError:\n    list(pure_python_tags(None))","preventionTips":["Default python_version to None rather than building an empty list.","Validate dynamic version lists are non-empty before passing.","Fall back to sys.version_info when filtering yields nothing."],"tags":["packaging","tags","validation","python-version"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}