{"id":"e0648f2efadbbaa4","repo":"pypa/pip","slug":"invalid-type-string-r-for-option-optname-you","errorCode":null,"errorMessage":"Invalid type {string!r} for option {optname}; you must give an integer value","messagePattern":"Invalid type (.+?) for option (.+?); you must give an integer value","errorType":"exception","errorClass":"OptionError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/util.py","lineNumber":88,"sourceCode":"    elif not isinstance(string, str):\n        raise OptionError(f'Invalid type {string!r} for option {optname}; use '\n                          '1/0, yes/no, true/false, on/off')\n    elif string.lower() in ('1', 'yes', 'true', 'on'):\n        return True\n    elif string.lower() in ('0', 'no', 'false', 'off'):\n        return False\n    else:\n        raise OptionError(f'Invalid value {string!r} for option {optname}; use '\n                          '1/0, yes/no, true/false, on/off')\n\n\ndef get_int_opt(options, optname, default=None):\n    \"\"\"As :func:`get_bool_opt`, but interpret the value as an integer.\"\"\"\n    string = options.get(optname, default)\n    try:\n        return int(string)\n    except TypeError:\n        raise OptionError(f'Invalid type {string!r} for option {optname}; you '\n                          'must give an integer value')\n    except ValueError:\n        raise OptionError(f'Invalid value {string!r} for option {optname}; you '\n                          'must give an integer value')\n\ndef get_list_opt(options, optname, default=None):\n    \"\"\"\n    If the key `optname` from the dictionary `options` is a string,\n    split it at whitespace and return it. If it is already a list\n    or a tuple, it is returned as a list.\n    \"\"\"\n    val = options.get(optname, default)\n    if isinstance(val, str):\n        return val.split()\n    elif isinstance(val, (list, tuple)):\n        return list(val)\n    else:\n        raise OptionError(f'Invalid type {val!r} for option {optname}; you '","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/util.py#L70-L106","documentation":"Pygments' get_int_opt raises OptionError ('Invalid type ...') when int(value) raises TypeError, which happens for values that cannot be converted at all because they are the wrong type (e.g. None, a list, a dict). The conversion attempt fails before any content parsing.","triggerScenarios":"Calling get_int_opt(options, optname) where options[optname] is None (no default), a list, a dict, or any non-numeric/non-string object; int() of such a value raises TypeError.","commonSituations":"A missing integer config key whose default resolved to None; a value loaded as a structured type (list/object) instead of a scalar; passing a float where int() on float would actually succeed, so this specifically signals a non-convertible type.","solutions":["Supply a numeric default (e.g. default=0) when calling get_int_opt.","Ensure the config source provides a str or int for that key.","Pre-validate that the value is not None before passing the options dict."],"exampleFix":"# before\nval = get_int_opt(opts, 'tabsize')  # opts['tabsize'] = None\n\n# after\nval = get_int_opt(opts, 'tabsize', default=8)","handlingStrategy":"type-guard","validationCode":"v = opts.get('tabsize')\nif not isinstance(v, (str, int)):\n    opts['tabsize'] = 8","typeGuard":"def is_int_option_value(v) -> bool:\n    return v is not None and isinstance(v, (str, int)) and not isinstance(v, bool)","tryCatchPattern":"from pip._vendor.pygments.util import OptionError\ntry:\n    val = get_int_opt(opts, 'tabsize', default=8)\nexcept OptionError:\n    val = 8","preventionTips":["Always supply an integer default to get_int_opt.","Reject None for numeric keys at the config boundary."],"tags":["pygments","config","validation","types"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}