{"id":"2d92564701aa430d","repo":"pypa/pip","slug":"invalid-value-string-r-for-option-optname-you","errorCode":null,"errorMessage":"Invalid value {string!r} for option {optname}; you must give an integer value","messagePattern":"Invalid value (.+?) for option (.+?); you must give an integer value","errorType":"exception","errorClass":"OptionError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/util.py","lineNumber":91,"sourceCode":"    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 '\n                          'must give a list value')\n\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/util.py#L73-L109","documentation":"Pygments' get_int_opt raises OptionError ('Invalid value ...') when int(value) raises ValueError: the value is a string (or other int-convertible type) whose content is not a valid integer, e.g. 'abc', '1.5', or ''.","triggerScenarios":"Calling get_int_opt with options[optname] set to a non-numeric string such as 'wide', '1.0', or an empty string; common when reading a free-text field that is expected to be numeric.","commonSituations":"Config files with units or text in a numeric field; user-supplied CLI values not pre-validated; locale-specific number formats ('1,000').","solutions":["Set the value to a base-10 integer string or int.","Strip non-digit characters before passing the options dict.","Provide a sensible integer default and omit the key when unsure."],"exampleFix":"# before\nopts['tabsize'] = 'wide'\nval = get_int_opt(opts, 'tabsize')\n\n# after\nopts['tabsize'] = '4'\nval = get_int_opt(opts, 'tabsize')","handlingStrategy":"validation","validationCode":"raw = opts.get('tabsize')\nif not str(raw).lstrip('-').isdigit():\n    raise ValueError('tabsize must be an integer')\nget_int_opt(opts, 'tabsize')","typeGuard":"def is_int_str(v: str) -> bool:\n    return isinstance(v, str) and v.lstrip('-').isdigit()","tryCatchPattern":"from pip._vendor.pygments.util import OptionError\ntry:\n    val = get_int_opt(opts, 'tabsize')\nexcept OptionError:\n    val = 8","preventionTips":["Pre-validate numeric fields from config files/CLI with str.isdigit.","Strip units and whitespace before validation."],"tags":["pygments","config","validation"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}