{"id":"ee86a88f9353c081","repo":"pypa/pip","slug":"unexpected-type-type-value-name-expected-s","errorCode":null,"errorMessage":"Unexpected type {type(value).__name__} (expected Sequence)","messagePattern":"Unexpected type (.+?) \\(expected Sequence\\)","errorType":"validation","errorClass":"PylockValidationError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/packaging/pylock.py","lineNumber":126,"sourceCode":"    return value\n\n\ndef _get_required(d: Mapping[str, Any], expected_type: type[_T], key: str) -> _T:\n    \"\"\"Get a required value from the dictionary and verify it's the expected type.\"\"\"\n    if (value := _get(d, expected_type, key)) is None:\n        raise _PylockRequiredKeyError(key)\n    return value\n\n\ndef _get_sequence(\n    d: Mapping[str, Any], expected_item_type: type[_T], key: str\n) -> Sequence[_T] | None:\n    \"\"\"Get a list value from the dictionary and verify it's the expected items type.\"\"\"\n    if (value := _get(d, Sequence, key)) is None:  # type: ignore[type-abstract]\n        return None\n    if isinstance(value, (str, bytes)):\n        # special case: str and bytes are Sequences, but we want to reject it\n        raise PylockValidationError(\n            f\"Unexpected type {type(value).__name__} (expected Sequence)\",\n            context=key,\n        )\n    for i, item in enumerate(value):\n        if not isinstance(item, expected_item_type):\n            raise PylockValidationError(\n                f\"Unexpected type {type(item).__name__} \"\n                f\"(expected {expected_item_type.__name__})\",\n                context=f\"{key}[{i}]\",\n            )\n    return value\n\n\ndef _get_as(\n    d: Mapping[str, Any],\n    expected_type: type[_T],\n    target_type: Callable[[_T], _T2],\n    key: str,","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/packaging/pylock.py#L108-L144","documentation":"Raised as PylockValidationError by _get_sequence in packaging.pylock when a field that must be a list/sequence is instead a str or bytes. str and bytes are technically Sequences in Python, but pylock rejects them to prevent silent character-by-character iteration; the expected value is a real TOML array.","triggerScenarios":"Loading pylock.toml where 'dependencies = \\\"foo\\\"' (string instead of array), 'wheels = \\\"pkg.whl\\\"', or any array field is given a scalar string. The error context identifies the key.","commonSituations":"Hand-writing TOML and forgetting the array brackets; converting from a format that collapses single-element lists to scalars; typos like wheels = pkg.whl without quotes/brackets.","solutions":["Wrap the value in TOML array brackets: dependencies = [\\\"foo\\\"], wheels = [\\\"pkg-1.0.whl\\\"].","Regenerate the lockfile with a spec-compliant tool.","Validate the TOML structure (arrays for sequence fields) before calling PylockFile.from_dict.","Catch PylockValidationError and point the user at the key in e.context."],"exampleFix":"# before\ndependencies = \\\"requests\\\"\n# after\ndependencies = [\\\"requests\\\"]","handlingStrategy":"type-guard","validationCode":"from collections.abc import Sequence\n\ndef is_real_sequence(v) -> bool:\n    return isinstance(v, Sequence) and not isinstance(v, (str, bytes))","typeGuard":"from collections.abc import Sequence\nfrom typing import Any\n\ndef is_sequence_field(value: Any) -> bool:\n    return isinstance(value, Sequence) and not isinstance(value, (str, bytes))","tryCatchPattern":"from packaging.pylock import PylockValidationError\ntry:\n    PylockFile.from_dict(data)\nexcept PylockValidationError as e:\n    if 'expected Sequence' in str(e):\n        wrap_in_array(e.context)","preventionTips":["Always use TOML array brackets for sequence fields.","Validate sequence fields are not str/bytes before loading.","Use a resolver rather than hand-writing TOML.","Catch and surface e.context to the user."],"tags":["pylock","pep771","toml","type-checking"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}