{"record":{"id":"971493355c344d79","repo":"deepfakes/faceswap","slug":"self-name-list-values-should-be-set-as-a-str","errorCode":null,"errorMessage":"[{self._name}] List values should be set as a Str or List. Got {type(value)} ({value})","messagePattern":"\\[(.+?)\\] List values should be set as a Str or List\\. Got (.+?) \\((.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/config/objects.py","lineNumber":385,"sourceCode":"        \"\"\"Set the item's option value\n\n        Parameters\n        ----------\n        value\n            The value to set this item to. Must be of type :attr:`datatype`\n\n        Raises\n        ------\n        ValueError\n            If the given value does not pass type and content validation checks\n        \"\"\"\n        if not self._name:\n            raise ValueError(\"The name of this object should have been set before any value is\"\n                             \"added\")\n\n        if self.datatype is list:\n            if not isinstance(value, (str, list)):\n                raise ValueError(f\"[{self._name}] List values should be set as a Str or List. Got \"\n                                 f\"{type(value)} ({value})\")\n            value = cast(T, self._parse_list(value))\n\n        if not isinstance(value, self.datatype):\n            raise ValueError(\n                f\"[{self._name}] Expected {self.datatype} got {type(value)} ({value})\")\n\n        if isinstance(self.choices, list) and self.choices:\n            assert isinstance(value, (list, str))\n            value = cast(T, self._validate_selection(value))\n\n        if self.choices == \"colorchooser\":\n            assert isinstance(value, str)\n            if not value.startswith(\"#\") or len(value) != 7:\n                raise ValueError(f\"Hex color codes should start with a '#' and be 6 \"\n                                 f\"characters long. Got: '{value}'\")\n\n        self._value = value","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/lib/config/objects.py#L367-L403","documentation":"Generic datatype check in ConfigOption.validate: after list handling, the value must be an instance of the option's declared datatype (str/int/float/bool/list). Otherwise ValueError is raised with the expected vs received type, prefixed by the option's name for easy identification.","triggerScenarios":"option.set(value) where datatype is int but a str '2' is passed; datatype bool with 1/0; datatype float with an int where the option declared float (isinstance passes for int/float pairings only in one direction); datatype str with bytes.","commonSituations":"Hand-editing a plugin .ini where a quoted number stays a string; programmatic config writers using unconverted values from argparse or JSON; plugin authors declaring datatype=int but defaulting to '128'.","solutions":["Convert the value to the option's datatype before setting: int('2'), float(1), bool flags via strtobool semantics","Inspect the option (option.datatype) and correct the value or the option's declared datatype","For .ini files, remove quotes around numerics so configparser+Faceswap coerces correctly"],"exampleFix":"# before\noption.datatype is int\noption.set(\"256\")  # -> [name] Expected <class 'int'> got <class 'str'> ('256')\n\n# after\noption.set(int(\"256\"))","handlingStrategy":"type-guard","validationCode":"def coerce_list_value(value):\n    if isinstance(value, str):\n        return value\n    if isinstance(value, (list, tuple, set)):\n        return list(value)\n    raise TypeError(f\"cannot coerce {type(value).__name__} to list\")\n\noption.set(coerce_list_value(value))","typeGuard":"def is_list_option_value(v) -> bool:\n    \"\"\"True when ConfigOption.set accepts v for a list-datatype option.\"\"\"\n    return isinstance(v, (str, list))","tryCatchPattern":"try:\n    option.set(value)\nexcept ValueError as err:\n    if \"List values should be set as a Str or List\" in str(err):\n        option.set(list(value) if not isinstance(value, str) else value)\n    else:\n        raise","preventionTips":["Always materialize tuples/sets to list before setting list options","Accept comma-separated strings as the canonical serialized form","Unit-test config setters with str, list and tuple inputs"],"tags":["faceswap","config","validation","type-coercion"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}