{"record":{"id":"3bdcaf58c0060d1e","repo":"ultralytics/ultralytics","slug":"ultralytics-setting-k-must-be-t-name-t","errorCode":null,"errorMessage":"Ultralytics setting '{k}' must be '{t.__name__}' type, not '{type(v).__name__}'. {self.help_msg}","messagePattern":"Ultralytics setting '(.+?)' must be '(.+?)' type, not '(.+?)'\\. (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ultralytics/utils/__init__.py","lineNumber":1475,"sourceCode":"                f\"must be different than 'runs_dir: {self.get('runs_dir')}'. \"\n                f\"Please change one to avoid possible issues during training. {self.help_msg}\"\n            )\n\n    def __setitem__(self, key, value):\n        \"\"\"Update one key: value pair.\"\"\"\n        self.update({key: value})\n\n    def update(self, *args, **kwargs):\n        \"\"\"Update settings, validating keys and types.\"\"\"\n        for arg in args:\n            if isinstance(arg, dict):\n                kwargs.update(arg)\n        for k, v in kwargs.items():\n            if k not in self.defaults:\n                raise KeyError(f\"No Ultralytics setting '{k}'. {self.help_msg}\")\n            t = type(self.defaults[k])\n            if not isinstance(v, t):\n                raise TypeError(\n                    f\"Ultralytics setting '{k}' must be '{t.__name__}' type, not '{type(v).__name__}'. {self.help_msg}\"\n                )\n        super().update(*args, **kwargs)\n\n    def reset(self):\n        \"\"\"Reset the settings to default and save them.\"\"\"\n        self.clear()\n        self.update(self.defaults)\n\n\ndef deprecation_warn(arg, new_arg=None):\n    \"\"\"Issue a deprecation warning when a deprecated argument is used, suggesting an updated argument.\"\"\"\n    msg = f\"'{arg}' is deprecated and will be removed in the future.\"\n    if new_arg is not None:\n        msg += f\" Use '{new_arg}' instead.\"\n    LOGGER.warning(msg)\n\n","sourceCodeStart":1457,"sourceCodeEnd":1493,"githubUrl":"https://github.com/ultralytics/ultralytics/blob/0449ea011cfd6c9a0d50a0bf1043aca5190cd476/ultralytics/utils/__init__.py#L1457-L1493","documentation":"Raised by SettingsManager.update when a key is valid but the value's Python type differs from the type of that key's default. Each settings key has a fixed expected type (bool for sync, str for api_key/dirs, etc.) and the manager enforces isinstance(v, type(defaults[k])) on every update.","triggerScenarios":"Passing a string where a bool is expected: `yolo settings sync=False` from a CLI script that hands the literal string 'False' to update; passing int for a str-typed key; passing a Path instead of str for datasets_dir.","commonSituations":"Wrapping the yolo CLI in shell scripts and forwarding untyped string arguments into SETTINGS.update; JSON-loaded settings where booleans arrive as strings; programmatic updates that skip coercion.","solutions":["Coerce to the default's type before updating — check SETTINGS.defaults[k] for the expected type.","For booleans coming from CLI/env, parse first: value in {'true','1','yes'} style logic or argparse type=bool handling.","Run `yolo settings` to confirm the value stuck after fixing."],"exampleFix":"# before\nSETTINGS.update({\"sync\": \"False\"})  # str vs bool -> TypeError\n\n# after\nSETTINGS.update({\"sync\": False})","handlingStrategy":"validation","validationCode":"from ultralytics.utils import SETTINGS\n\ndef typed_update(key, value):\n    t = type(SETTINGS.defaults[key])  # KeyError here means bad key — handle separately\n    SETTINGS.update({key: t(value)})  # e.g. t='bool' -> careful: bool('False') is True; parse explicitly below\n\n# explicit bool parsing for strings:\ndef parse_bool(v):\n    return v if isinstance(v, bool) else str(v).strip().lower() in {\"1\", \"true\", \"yes\"}","typeGuard":"def matches_setting_type(key, value) -> bool:\n    from ultralytics.utils import SETTINGS\n    return key in SETTINGS.defaults and isinstance(value, type(SETTINGS.defaults[key]))","tryCatchPattern":"try:\n    SETTINGS.update({\"sync\": value})\nexcept TypeError as e:\n    raise TypeError(f\"wrong type for sync: {e}\") from e","preventionTips":["When forwarding CLI/env values into SETTINGS, convert strings to the default's type first (especially booleans: 'False' is truthy if you rely on bool()).","After scripted settings changes, run `yolo settings` to verify values took effect."],"tags":["settings","type-check","typeerror"],"backgroundTag":null,"analyzedSha":"0449ea011cfd6c9a0d50a0bf1043aca5190cd476","analyzedAt":"2026-08-15T02:34:13.413Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}