{"id":"3b956da21a2fb882","repo":"pypa/pip","slug":"invalid-type-val-r-for-option-optname-you-mus","errorCode":null,"errorMessage":"Invalid type {val!r} for option {optname}; you must give a list value","messagePattern":"Invalid type (.+?) for option (.+?); you must give a list value","errorType":"exception","errorClass":"OptionError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/util.py","lineNumber":106,"sourceCode":"        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\ndef docstring_headline(obj):\n    if not obj.__doc__:\n        return ''\n    res = []\n    for line in obj.__doc__.strip().splitlines():\n        if line.strip():\n            res.append(\" \" + line.strip())\n        else:\n            break\n    return ''.join(res).lstrip()\n\n\ndef make_analysator(f):\n    \"\"\"Return a static text analyser function that returns float values.\"\"\"\n    def text_analyse(text):","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/util.py#L88-L124","documentation":"Pygments' get_list_opt raises OptionError when the option value is neither a string (which would be whitespace-split) nor a list/tuple. Any other type (None, int, dict) is rejected because it cannot be interpreted as a list.","triggerScenarios":"Calling get_list_opt(options, optname) where options[optname] is None (and no default), an int, or a dict; the function only accepts str, list, or tuple.","commonSituations":"A missing list option defaulted to None; a scalar accidentally supplied where a list was expected; JSON config yielding null or a number for what should be a list field.","solutions":["Pass the value as a string (split on whitespace) or as a list/tuple.","Provide a default list when the key may be absent.","Normalize the config source so the key always yields a list."],"exampleFix":"# before\nopts['filenames'] = None\nval = get_list_opt(opts, 'filenames')\n\n# after\nopts['filenames'] = '*.txt *.md'\nval = get_list_opt(opts, 'filenames')","handlingStrategy":"type-guard","validationCode":"v = opts.get('filenames')\nif not isinstance(v, (str, list, tuple)):\n    opts['filenames'] = []","typeGuard":"def is_list_option_value(v) -> bool:\n    return isinstance(v, (str, list, tuple))","tryCatchPattern":"from pip._vendor.pygments.util import OptionError\ntry:\n    val = get_list_opt(opts, 'filenames', default=[])\nexcept OptionError:\n    val = []","preventionTips":["Provide a list default for optional list keys.","Wrap single scalar values in a list at the config boundary."],"tags":["pygments","config","validation","types"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}