{"record":{"id":"ebf6886f6860904c","repo":"pytest-dev/pytest","slug":"expected-a-float-string-for-option-name-of-type","errorCode":null,"errorMessage":"Expected a float string for option {name} of type float, but got: {value!r}","messagePattern":"Expected a float string for option (.+?) of type float, but got: (.+?)","errorType":"exception","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":1937,"sourceCode":"            return shlex.split(value) if isinstance(value, str) else value\n        elif type == \"linelist\":\n            if isinstance(value, str):\n                return [t for t in map(lambda x: x.strip(), value.split(\"\\n\")) if t]\n            else:\n                return value\n        elif type == \"bool\":\n            return _strtobool(str(value).strip())\n        elif type == \"string\":\n            return value\n        elif type == \"int\":\n            if not isinstance(value, str):\n                raise TypeError(\n                    f\"Expected an int string for option {name} of type integer, but got: {value!r}\"\n                ) from None\n            return int(value)\n        elif type == \"float\":\n            if not isinstance(value, str):\n                raise TypeError(\n                    f\"Expected a float string for option {name} of type float, but got: {value!r}\"\n                ) from None\n            return float(value)\n        else:\n            return self._getini_unknown_type(name, type, value)\n\n    def _getini_toml(\n        self,\n        name: str,\n        canonical_name: str,\n        type: str,\n        value: object,\n        default: Any,\n    ):\n        \"\"\"Handle TOML config values with strict type validation and no coercion.\n\n        In TOML mode, values already have native types from TOML parsing.\n        We validate types match expectations exactly, including list items.","sourceCodeStart":1919,"sourceCodeEnd":1955,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/__init__.py#L1919-L1955","documentation":"Raised by _getini_ini() at config/__init__.py:1933-1936 when an ini option of type 'float' receives a value that is not a string. Like error 58, the function contract says INI-mode values are always str|list[str] (capture.py:1891-1895), so this is a defensive guard against pytest-internal bugs or direct injection into Config._inicfg. The outer handler at config/__init__.py:1847-1848 converts the TypeError to UsageError.","triggerScenarios":"Only reachable through non-standard code paths - e.g. faulthandler_timeout (faulthandler.py:27, default=0.0 float) being injected with a non-string value via a monkeypatch or a buggy custom config loader. capture.py:1934 checks `not isinstance(value, str)` and raises.","commonSituations":"Should not occur in normal use. If you hit it, a plugin or test is writing directly to Config._inicfg or the toml/ini loaders have been customized.","solutions":["Confirm no plugin is injecting non-string values into Config._inicfg for float-typed options","Provide the value as a string in the config file: faulthandler_timeout = 1.5","Report upstream if reached through normal pyproject.toml/pytest.ini loading"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if not isinstance(value, str):\n    value = str(value)","typeGuard":"def is_float_string(v) -> bool:\n    if not isinstance(v, str):\n        return False\n    try:\n        float(v); return True\n    except ValueError:\n        return False","tryCatchPattern":"from _pytest.config import UsageError\ntry:\n    val = config.getini('opt')\nexcept UsageError as e:\n    print(f'Internal: non-string reached float branch: {e}')","preventionTips":["Keep float-typed ini values as strings in test fixtures and config files","Avoid writing to Config._inicfg from plugins - use the public addini pipeline","Report upstream if this fires from standard pyproject.toml/pytest.ini loading"],"tags":["config","ini","float","defensive","internal"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}