{"record":{"id":"03718b22388715df","repo":"pypa/pip","slug":"expected-a-specifierset","errorCode":null,"errorMessage":"expected a SpecifierSet","messagePattern":"expected a SpecifierSet","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/packaging/specifiers.py","lineNumber":1145,"sourceCode":"\n    def to_range(self) -> ranges.VersionRange:\n        \"\"\"Return the :class:`~packaging.ranges.VersionRange` this set accepts.\n\n        An empty set yields the full range; an unsatisfiable set yields the\n        empty range. ``===`` specifiers contribute literal-string admission.\n\n        >>> SpecifierSet(\">=1.0,<2.0\").to_range()\n        <VersionRange '[1.0, 2.0.dev0)'>\n\n        .. versionadded:: 26.3\n        \"\"\"\n        from .ranges import VersionRange  # noqa: PLC0415\n\n        return VersionRange._from_specifier_set(self)\n\n    def _check_relation_operand(self, other: object) -> None:\n        if not isinstance(other, SpecifierSet):\n            raise TypeError(\"expected a SpecifierSet\")\n        if self._has_arbitrary or other._has_arbitrary:\n            raise ValueError(\"set relations do not support === specifiers\")\n\n    def is_subset(self, other: SpecifierSet) -> bool:\n        \"\"\"Return whether every version matching this set also matches other.\n\n        :raises ValueError:\n            If either set uses ``===`` specifiers, or the two sets were\n            given different ``prereleases`` arguments (unset on one side\n            counts as different).\n        :raises TypeError:\n            If other is not a :class:`SpecifierSet`.\n\n        >>> SpecifierSet(\">=3.12,<3.13\").is_subset(SpecifierSet(\">=3.12\"))\n        True\n        >>> SpecifierSet(\">=3.12\").is_subset(SpecifierSet(\">=3.12,<3.13\"))\n        False\n","sourceCodeStart":1127,"sourceCodeEnd":1163,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/packaging/specifiers.py#L1127-L1163","documentation":"Raised as TypeError by SpecifierSet._check_relation_operand (specifiers.py:1145), the guard invoked by is_subset/is_superset/is_disjoint/is_proper_subset relations. If the other operand is not an instance of SpecifierSet the method raises immediately before any range comparison. Passing a raw string, a Specifier, a list, or None all trigger it.","triggerScenarios":"SpecifierSet('>=3.12').is_subset('>=3.12') (passing a str instead of SpecifierSet); .is_superset(some_specifier) (a Specifier, not a set); .is_subset(None); passing a list of spec strings.","commonSituations":"Calling the new 26.3 set-relation API with values read from config (strings) without wrapping them; mixing Specifier and SpecifierSet in a comparison helper; type-mismatched helper functions that accept 'specifier-like' input.","solutions":["Wrap the operand: other = SpecifierSet(other) if isinstance(other, str) else other before calling the relation.","Ensure your helper always passes a SpecifierSet instance; convert at the boundary.","If other is already a single Specifier, wrap it: SpecifierSet(str(specifier)).","Add a type guard / isinstance check and raise a clearer domain-specific error before the call."],"exampleFix":"# before\nss = SpecifierSet('>=3.12')\nss.is_subset('>=3.12')  # TypeError: expected a SpecifierSet\n\n# after\nfrom packaging.specifiers import SpecifierSet\nother = SpecifierSet('>=3.12') if isinstance(other, str) else other\nss.is_subset(other)","handlingStrategy":"type-guard","validationCode":"from packaging.specifiers import SpecifierSet, Specifier\n\ndef to_specifierset(v) -> SpecifierSet:\n    if isinstance(v, str):\n        return SpecifierSet(v)\n    if isinstance(v, Specifier):\n        return SpecifierSet(str(v))\n    if isinstance(v, SpecifierSet):\n        return v\n    raise TypeError(f'expected SpecifierSet/str/Specifier, got {type(v)!r}')","typeGuard":"from packaging.specifiers import SpecifierSet\ndef is_specifierset(v) -> bool:\n    return isinstance(v, SpecifierSet)","tryCatchPattern":"try:\n    a.is_subset(other)\nexcept TypeError:\n    other = to_specifierset(other)\n    return a.is_subset(other)","preventionTips":["Always convert specifier-like inputs to SpecifierSet at the boundary.","Type-annotate relation helper params as SpecifierSet.","Unit-test the relation API with str, Specifier, and SpecifierSet inputs."],"tags":["packaging","specifiers","type-error","api-usage"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}