{"id":"fd7c1f3d2ca7035e","repo":"pypa/pip","slug":"invalid-value-string-r-for-option-optname-use","errorCode":null,"errorMessage":"Invalid value {string!r} for option {optname}; use 1/0, yes/no, true/false, on/off","messagePattern":"Invalid value (.+?) for option (.+?); use 1/0, yes/no, true/false, on/off","errorType":"exception","errorClass":"OptionError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/util.py","lineNumber":78,"sourceCode":"\n    The valid string values for ``True`` are ``1``, ``yes``, ``true`` and\n    ``on``, the ones for ``False`` are ``0``, ``no``, ``false`` and ``off``\n    (matched case-insensitively).\n    \"\"\"\n    string = options.get(optname, default)\n    if isinstance(string, bool):\n        return string\n    elif isinstance(string, int):\n        return bool(string)\n    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,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/util.py#L60-L96","documentation":"Pygments' get_bool_opt raises OptionError ('Invalid value ...') when the option value is a string that, after lowercasing, is not one of the recognized boolean literals (1/yes/true/on or 0/no/false/off). The type is acceptable (str) but the content is not a valid boolean spelling.","triggerScenarios":"Calling get_bool_opt with options[optname] set to a string like 'enable', 't', 'yep', or any non-recognized token; often from CLI flags or config files using a custom yes/no spelling.","commonSituations":"Config files using 'enable'/'disable' or 't'/'f'; localized values; trailing whitespace that wasn't stripped before validation.","solutions":["Use exactly one of: 1, yes, true, on (true) or 0, no, false, off (false), case-insensitive.","Strip/normalize the string before it reaches get_bool_opt.","Map your application's boolean spellings to the accepted set before building the options dict."],"exampleFix":"# before\nopts['nowrap'] = 'enable'\nval = get_bool_opt(opts, 'nowrap')\n\n# after\nopts['nowrap'] = 'on'\nval = get_bool_opt(opts, 'nowrap')","handlingStrategy":"validation","validationCode":"TRUE = {'1','yes','true','on'}\nFALSE = {'0','no','false','off'}\nraw = str(opts.get('nowrap','')).strip().lower()\nif raw not in TRUE and raw not in FALSE:\n    raise ValueError('nowrap must be a boolean literal')\nget_bool_opt(opts, 'nowrap')","typeGuard":"def is_valid_bool_str(v: str) -> bool:\n    return v.strip().lower() in {'1','yes','true','on','0','no','false','off'}","tryCatchPattern":"from pip._vendor.pygments.util import OptionError\ntry:\n    val = get_bool_opt(opts, 'nowrap')\nexcept OptionError:\n    val = False","preventionTips":["Normalize boolean config strings to the accepted set before passing them on.","Document the accepted literals in your config schema."],"tags":["pygments","config","validation"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}