{"record":{"id":"646972c60b7bf8f5","repo":"deepfakes/faceswap","slug":"self-name-expected-self-datatype-got-type","errorCode":null,"errorMessage":"[{self._name}] Expected {self.datatype} got {type(value)} ({value})","messagePattern":"\\[(.+?)\\] Expected (.+?) got (.+?) \\((.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/config/objects.py","lineNumber":390,"sourceCode":"            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\n\n    def set_name(self, name: str) -> None:\n        \"\"\"Set the logging name for this object for display purposes\n\n        Parameters","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/lib/config/objects.py#L372-L408","documentation":"ConfigOption.validate special-case for options whose choices == 'colorchooser' (GUI color pickers): the value must be a 7-character string starting with '#'. Values like 'ff0000' (missing hash), '#ff00' (too short) or '#ff0000ff' (8 digits) raise ValueError.","triggerScenarios":"Setting a colorchooser-typed option (e.g. mask/display colors in GUI plugins) with a bare hex string, an 8-digit ARGB hex, a CSS color name ('red'), or a value with trailing whitespace.","commonSituations":"Hand-editing an .ini and dropping the '#'; copying colors from CSS/design tools that emit #RGB or rgb() notation; scripts writing colors from libraries that use 0x-prefixed ints.","solutions":["Normalize to '#rrggbb' before setting: f\"#{value.lstrip('#')[:6].lower()}\" then verify len == 7","Convert from numeric colors: '#%02x%02x%02x' % (r, g, b)","Use the GUI colorchooser control, which always yields a valid string"],"exampleFix":"# before\noption.set(\"ff0000\")     # missing '#'\noption.set(\"00ff00ff\")   # 8 digits\n\n# after\nr, g, b = 255, 0, 0\noption.set(\"#%02x%02x%02x\" % (r, g, b))  # '#ff0000'","handlingStrategy":"type-guard","validationCode":"def coerce(value, datatype):\n    if datatype is bool and isinstance(value, str):\n        return value.strip().lower() in (\"true\", \"yes\", \"on\", \"1\")\n    if datatype in (int, float) and isinstance(value, str):\n        return datatype(value.strip('\"\\' '))\n    if datatype is str and isinstance(value, bytes):\n        return value.decode()\n    return value\n\noption.set(coerce(raw, option.datatype))","typeGuard":"def matches_datatype(value, datatype) -> bool:\n    \"\"\"True when value passes ConfigOption's isinstance check.\"\"\"\n    if datatype is float:\n        return isinstance(value, (int, float)) and not isinstance(value, bool)\n    if datatype is bool:\n        return isinstance(value, bool)\n    return isinstance(value, datatype)","tryCatchPattern":"try:\n    option.set(value)\nexcept ValueError as err:\n    if \"Expected\" in str(err):\n        option.set(coerce(value, option.datatype))\n    else:\n        raise","preventionTips":["Convert values to the option's declared datatype before set()","Never store numbers as quoted strings in plugin .ini files","Assert option.datatype when writing config writers programmatically"],"tags":["faceswap","config","color","hex","validation"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}