{"record":{"id":"cf8335de787324a3","repo":"pytest-dev/pytest","slug":"invalid-type-for-ini-option-name-r-type-r-e","errorCode":null,"errorMessage":"invalid type for ini option {name!r}: {type_!r} (expected one of {tags}, one of the types str, bool, int, float, a union of these types such as `int | str`, or a `Literal` of strings)","messagePattern":"invalid type for ini option (.+?): (.+?) \\(expected one of (.+?), one of the types str, bool, int, float, a union of these types such as `int \\| str`, or a `Literal` of strings\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/argparsing.py","lineNumber":74,"sourceCode":"#: ``int | str``).\nIniType: TypeAlias = _IniTypeTag | _IniLiteral | tuple[_IniTypeTag | _IniLiteral, ...]\n\n#: Maps each string tag or plain Python type accepted by :meth:`Parser.addini`\n#: for its ``type`` argument to the normalized string tag.\n_INI_TYPES: dict[object, _IniTypeTag] = {tag: tag for tag in get_args(_IniTypeTag)} | {\n    str: \"string\",\n    bool: \"bool\",\n    int: \"int\",\n    float: \"float\",\n}\n\n\ndef _ini_type_to_tag(name: str, type_: object) -> _IniTypeTag:\n    \"\"\"Normalize one member of an `addini(type=...)` argument to a string tag.\"\"\"\n    try:\n        return _INI_TYPES[type_]\n    except (KeyError, TypeError):  # TypeError: unhashable type_\n        raise ValueError(\n            f\"invalid type for ini option {name!r}: {type_!r} (expected one of \"\n            f\"{', '.join(repr(tag) for tag in get_args(_IniTypeTag))}, one of \"\n            \"the types str, bool, int, float, a union of these types such as \"\n            \"`int | str`, or a `Literal` of strings)\"\n        ) from None\n\n\ndef _ini_type_to_member(name: str, type_: object) -> _IniTypeTag | _IniLiteral:\n    \"\"\"Normalize one member of an `addini(type=...)` argument.\"\"\"\n    if get_origin(type_) is Literal:\n        choices = get_args(type_)\n        if not all(isinstance(choice, str) for choice in choices):\n            raise ValueError(\n                f\"invalid type for ini option {name!r}: Literal choices \"\n                f\"must be strings, got {choices!r}\"\n            )\n        return _IniLiteral(choices)\n    return _ini_type_to_tag(name, type_)","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/argparsing.py#L56-L92","documentation":"Raised by _ini_type_to_tag() during addini() when the type argument (or a member of a union type) is not one of the recognized ini types. Valid types are the Python types str, bool, int, float, or the string tags 'string','bool','int','float','paths','pathlist','args','linelist'. The error lists the valid tags and explains union/Literal syntax.","triggerScenarios":"Calling parser.addini('name', type=list) or type=dict or type=SomeEnum — none of these are recognized. Also triggered by passing an unhashable type (TypeError in the dict lookup). The _INI_TYPES dict lookup raises KeyError or TypeError.","commonSituations":"Passing Python collection types (list, dict, set, tuple) as the type. Passing an Enum or arbitrary class. Passing a non-type object. Using a union that includes an invalid member (e.g., int | list).","solutions":["Use one of the valid string tags: 'string', 'bool', 'int', 'float', 'paths', 'pathlist', 'args', 'linelist'","Or use the corresponding Python type: str, bool, int, float","For multiple string choices, use Literal['a','b','c']","For unions, use only valid members: int | str"],"exampleFix":"# before\nparser.addini('my_opt', type=list)\n\n# after\nparser.addini('my_opt', type='linelist')","handlingStrategy":"type-guard","validationCode":"VALID_INI_TAGS = {'string', 'bool', 'int', 'float', 'paths', 'pathlist', 'args', 'linelist'}\nVALID_INI_TYPES = {str, bool, int, float}\ndef validate_addini_type(type_: object) -> bool:\n    if type_ is None:\n        return True\n    if type_ in VALID_INI_TAGS or type_ in VALID_INI_TYPES:\n        return True\n    return False","typeGuard":"from typing import get_args, get_origin, Literal\nVALID_TAGS = {'string', 'bool', 'int', 'float', 'paths', 'pathlist', 'args', 'linelist'}\nVALID_TYPES = {str, bool, int, float}\ndef is_valid_ini_type_member(t: object) -> bool:\n    return t in VALID_TAGS or t in VALID_TYPES","tryCatchPattern":null,"preventionTips":["Use one of: str, bool, int, float, or a string tag like 'paths', 'linelist'","Do not pass list, dict, set, tuple, or arbitrary classes as the type","For unions/Literals, use only valid scalar members"],"tags":["pytest","config","addini","type-validation","plugin-api"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}