{"record":{"id":"67e621e3e14b43b6","repo":"SeleniumHQ/selenium","slug":"self-name-must-be-of-type-self-expected-type","errorCode":null,"errorMessage":"{self.name} must be of type {self.expected_type}","messagePattern":"(.+?) must be of type (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/safari/options.py","lineNumber":54,"sourceCode":"\n    Example:\n        `self.automatic_inspection` = True\n        (`__set__` method sets/updates the value of the key `safari:automaticInspection` in `_caps`\n            dictionary in `Options` class)\n    \"\"\"\n\n    def __init__(self, name, expected_type):\n        self.name = name\n        self.expected_type = expected_type\n\n    def __get__(self, obj, cls):\n        if self.name == \"Safari Technology Preview\":\n            return obj._caps.get(\"browserName\") == self.name\n        return obj._caps.get(self.name)\n\n    def __set__(self, obj, value):\n        if not isinstance(value, self.expected_type):\n            raise TypeError(f\"{self.name} must be of type {self.expected_type}\")\n        if self.name == \"Safari Technology Preview\":\n            obj._caps[\"browserName\"] = self.name if value else \"safari\"\n        else:\n            obj._caps[self.name] = value\n\n\nclass Options(ArgOptions):\n    # @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari\n    AUTOMATIC_INSPECTION = \"safari:automaticInspection\"\n    AUTOMATIC_PROFILING = \"safari:automaticProfiling\"\n    SAFARI_TECH_PREVIEW = \"Safari Technology Preview\"\n\n    # creating descriptor objects\n    automatic_inspection = _SafariOptionsDescriptor(AUTOMATIC_INSPECTION, bool)\n    \"\"\"Whether to enable automatic inspection.\"\"\"\n\n    automatic_profiling = _SafariOptionsDescriptor(AUTOMATIC_PROFILING, bool)\n    \"\"\"Whether to enable automatic profiling.\"\"\"","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/safari/options.py#L36-L72","documentation":"Safari Options uses OptionDescriptor instances for safari-specific capabilities. __set__ enforces that the assigned value matches expected_type; a mismatch raises TypeError naming the capability and the expected type.","triggerScenarios":"Setting a safari option (e.g. safari:automaticInspection / safari:automaticProfiling which expect bool) with the wrong Python type - a string, None, or int where bool is required.","commonSituations":"Loading capabilities from JSON/YAML where booleans arrive as strings, or assuming these accept truthy values.","solutions":["Coerce the value to the descriptor's expected_type before assignment.","Inspect the Options class constants (AUTOMATIC_INSPECTION, AUTOMATIC_PROFILING, etc.) to learn which options exist and their types.","Load config with proper typing so json booleans stay bool, not str."],"exampleFix":"# before\nopts = Options()\nopts[\"safari:automaticInspection\"] = \"true\"   # str, not bool\n\n# after\nopts = Options()\nopts[\"safari:automaticInspection\"] = True","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def coerce_bool(v):\n    if isinstance(v, bool):\n        return v\n    if isinstance(v, str) and v.lower() in (\"true\", \"false\"):\n        return v.lower() == \"true\"\n    raise TypeError(f\"expected bool, got {type(v)}\")","tryCatchPattern":null,"preventionTips":["Always pass native bool for safari toggle capabilities.","Validate config-derived values against the descriptor type before setting."],"tags":["safari","options","type-validation","capabilities"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}