{"record":{"id":"f85976e4bc541ac4","repo":"openai/whisper","slug":"expected-one-of-set-str2val-keys-got-string","errorCode":null,"errorMessage":"Expected one of {set(str2val.keys())}, got {string}","messagePattern":"Expected one of (.+?), got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"whisper/utils.py","lineNumber":34,"sourceCode":"\nelse:\n\n    def make_safe(string):\n        # utf-8 can encode any Unicode code point, so no need to do the round-trip encoding\n        return string\n\n\ndef exact_div(x, y):\n    assert x % y == 0\n    return x // y\n\n\ndef str2bool(string):\n    str2val = {\"True\": True, \"False\": False}\n    if string in str2val:\n        return str2val[string]\n    else:\n        raise ValueError(f\"Expected one of {set(str2val.keys())}, got {string}\")\n\n\ndef optional_int(string):\n    return None if string == \"None\" else int(string)\n\n\ndef optional_float(string):\n    return None if string == \"None\" else float(string)\n\n\ndef compression_ratio(text) -> float:\n    text_bytes = text.encode(\"utf-8\")\n    return len(text_bytes) / len(zlib.compress(text_bytes))\n\n\ndef format_timestamp(\n    seconds: float, always_include_hours: bool = False, decimal_marker: str = \".\"\n):","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/openai/whisper/blob/5f86d1d86363843179951550570367b37c5d6f78/whisper/utils.py#L16-L52","documentation":"str2bool is the argparse `type` used for boolean CLI flags such as --verbose, --condition_on_previous_text, and --fp16. It accepts only the exact strings 'True' and 'False' (case-sensitive); anything else — 'true', '1', 'yes', 'false' — raises ValueError, which argparse reports as 'invalid str2bool value'.","triggerScenarios":"whisper audio.mp3 --verbose true (lowercase), --verbose False vs --verbose false, --fp16 0, or a shell script passing $FLAG where FLAG=yes. Any boolean flag with a non-canonical string triggers it during argument parsing.","commonSituations":"Shell scripts and YAML-driven invocations using lowercase booleans; users expecting flag-style (--verbose) or 0/1 semantics; environment-variable-derived values passed verbatim.","solutions":["Use exactly 'True' or 'False': whisper audio.mp3 --verbose False","Omit the flag to accept the default shown in --help","In scripts, normalize first: FLAG=$([ \"$FLAG\" = \"true\" ] && echo True || echo False)"],"exampleFix":"# before\nwhisper audio.mp3 --verbose true --fp16 0  # invalid str2bool value\n\n# after\nwhisper audio.mp3 --verbose False --fp16 False","handlingStrategy":"validation","validationCode":"def cli_bool(v: str) -> str:\n    return \"True\" if str(v).strip().lower() in (\"true\", \"1\", \"yes\") else \"False\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass only 'True'/'False' to whisper CLI boolean flags — the parser is case-sensitive","Normalize booleans from env vars/scripts before building the CLI command line"],"tags":["cli","argparse","boolean-parsing","configuration"],"backgroundTag":null,"analyzedSha":"5f86d1d86363843179951550570367b37c5d6f78","analyzedAt":"2026-08-14T18:53:59.547Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}