{"record":{"id":"1c3a8f585b7a37fa","repo":"pypa/pip","slug":"invalid-truth-value-val-r","errorCode":null,"errorMessage":"invalid truth value {val!r}","messagePattern":"invalid truth value (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/utils/misc.py","lineNumber":298,"sourceCode":"    \"\"\"Ask for a password interactively.\"\"\"\n    _check_no_input(message)\n    return getpass.getpass(message)\n\n\ndef strtobool(val: str) -> int:\n    \"\"\"Convert a string representation of truth to true (1) or false (0).\n\n    True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values\n    are 'n', 'no', 'f', 'false', 'off', and '0'.  Raises ValueError if\n    'val' is anything else.\n    \"\"\"\n    val = val.lower()\n    if val in (\"y\", \"yes\", \"t\", \"true\", \"on\", \"1\"):\n        return 1\n    elif val in (\"n\", \"no\", \"f\", \"false\", \"off\", \"0\"):\n        return 0\n    else:\n        raise ValueError(f\"invalid truth value {val!r}\")\n\n\ndef format_size(bytes: float) -> str:\n    if bytes > 1000 * 1000:\n        return f\"{bytes / 1000.0 / 1000:.1f} MB\"\n    elif bytes > 10 * 1000:\n        return f\"{int(bytes / 1000)} kB\"\n    elif bytes > 1000:\n        return f\"{bytes / 1000.0:.1f} kB\"\n    else:\n        return f\"{int(bytes)} bytes\"\n\n\ndef tabulate(rows: Iterable[Iterable[Any]]) -> tuple[list[str], list[int]]:\n    \"\"\"Return a list of formatted rows and a list of column sizes.\n\n    For example::\n","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/utils/misc.py#L280-L316","documentation":"Raised as ValueError by strtobool (misc.py:298) when the input string does not match any recognised truthy or falsy value. strtobool accepts 'y/yes/t/true/on/1' (returns 1) and 'n/no/f/false/off/0' (returns 0); any other input triggers this error. The function lowercases the input first, so case is not an issue, but any other content (empty string, typos, integer representations beyond 0/1) is rejected.","triggerScenarios":"strtobool is called with an unrecognised string, typically originating from an environment variable or CLI argument that pip passes through. For example PIP_* boolean flags parsed via strtobool where the user set an invalid value.","commonSituations":"Setting a boolean pip option via environment variable with an invalid value (PIP_VERIFY_CERTS=yes_no, PIP_QUIET=2). Passing --no-color when the underlying config expects strtobool-parseable input. Third-party tools or wrappers feeding unvalidated strings into pip config.","solutions":["Set the environment variable or argument to a recognised value: one of yes/no/true/false/on/off/1/0 (case-insensitive).","Validate the value before passing it to pip: ensure it matches the accepted set.","If the value comes from user input in your own tool, normalise it to 'true' or 'false' before setting the pip env var.","Unset the variable entirely if pip's default behaviour is acceptable."],"exampleFix":"// before\nexport PIP_DISABLE_PIP_VERSION_CHECK=yeah\n\n// after\nexport PIP_DISABLE_PIP_VERSION_CHECK=yes","handlingStrategy":"validation","validationCode":"def normalize_bool_env(value: str) -> str:\n    \"\"\"Normalize arbitrary input to a strtobool-compatible value.\"\"\"\n    valid_true = {'y', 'yes', 't', 'true', 'on', '1'}\n    valid_false = {'n', 'no', 'f', 'false', 'off', '0'}\n    low = value.strip().lower()\n    if low in valid_true:\n        return '1'\n    if low in valid_false:\n        return '0'\n    raise ValueError(f'{value!r} is not a valid boolean; use yes/no/true/false/on/off/1/0')","typeGuard":"def is_valid_strtobool(value: str) -> bool:\n    \"\"\"True if pip's strtobool will accept the value without error.\"\"\"\n    return value.strip().lower() in {\n        'y', 'yes', 't', 'true', 'on', '1',\n        'n', 'no', 'f', 'false', 'off', '0',\n    }","tryCatchPattern":"try:\n    from pip._internal.utils.misc import strtobool\n    result = strtobool(user_input)\nexcept ValueError:\n    result = None  # or prompt for valid input","preventionTips":["Validate boolean env vars before setting them for pip.","Use a configuration wrapper that normalizes yes/no values.","Document the exact accepted values (yes/no/true/false/on/off/1/0) in your setup docs."],"tags":["validation","configuration","strtobool","environment"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}