{"record":{"id":"bb17cad10f791d7f","repo":"TheAlgorithms/Python","slug":"invalid-from-type-value-from-type-r-supporte","errorCode":null,"errorMessage":"Invalid 'from_type' value: {from_type!r}  Supported values are:\n{', '.join(PRESSURE_CONVERSION)}","messagePattern":"Invalid 'from_type' value: (.+?)  Supported values are:\n(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"conversions/pressure_conversions.py","lineNumber":68,"sourceCode":"    0.986923\r\n    >>> pressure_conversion(3, \"kilopascal\", \"bar\")\r\n    0.029999991892499998\r\n    >>> pressure_conversion(2, \"megapascal\", \"psi\")\r\n    290.074434314\r\n    >>> pressure_conversion(4, \"psi\", \"torr\")\r\n    206.85984\r\n    >>> pressure_conversion(1, \"inHg\", \"atm\")\r\n    0.0334211\r\n    >>> pressure_conversion(1, \"torr\", \"psi\")\r\n    0.019336718261000002\r\n    >>> pressure_conversion(4, \"wrongUnit\", \"atm\")\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: Invalid 'from_type' value: 'wrongUnit'  Supported values are:\r\n    atm, pascal, bar, kilopascal, megapascal, psi, inHg, torr\r\n    \"\"\"\r\n    if from_type not in PRESSURE_CONVERSION:\r\n        raise ValueError(\r\n            f\"Invalid 'from_type' value: {from_type!r}  Supported values are:\\n\"\r\n            + \", \".join(PRESSURE_CONVERSION)\r\n        )\r\n    if to_type not in PRESSURE_CONVERSION:\r\n        raise ValueError(\r\n            f\"Invalid 'to_type' value: {to_type!r}.  Supported values are:\\n\"\r\n            + \", \".join(PRESSURE_CONVERSION)\r\n        )\r\n    return (\r\n        value\r\n        * PRESSURE_CONVERSION[from_type].from_factor\r\n        * PRESSURE_CONVERSION[to_type].to_factor\r\n    )\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    import doctest\r\n\r","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/pressure_conversions.py#L50-L86","documentation":"Raised by pressure_conversion() in conversions/pressure_conversions.py when from_type is not a key in PRESSURE_CONVERSION. Supported keys are atm, pascal, bar, kilopascal, megapascal, psi, inHg, torr (exact case). The error message embeds the full supported list, so it is self-documenting at runtime.","triggerScenarios":"Calling pressure_conversion(1, 'wrongUnit', 'atm'), using 'Pa' or 'PSI' instead of exact 'pascal'/'psi', or a typo like 'inhg' vs 'inHg'.","commonSituations":"Mapping user-facing unit names (e.g. 'mmHg', 'atmosphere') directly to this API without a translation table; case mismatches; unit catalogs from another library that use SI symbols (Pa, bar, kPa) instead of these spellings.","solutions":["Use one of the exact keys: atm, pascal, bar, kilopascal, megapascal, psi, inHg, torr.","Lowercase/normalize the unit string and map aliases (e.g. {'pa': 'pascal', 'kpa': 'kilopascal'}) before calling.","If mmHg or other units are needed, convert to torr first (1 mmHg = 1 torr)."],"exampleFix":"# before\npressure_conversion(1, 'Pa', 'atm')  # ValueError: Invalid 'from_type' value: 'Pa'\n\n# after\nALIASES = {'pa': 'pascal', 'kpa': 'kilopascal', 'mpa': 'megapascal', 'inhg': 'inHg'}\nunit = ALIASES.get('Pa'.lower(), 'Pa')\npressure_conversion(1, unit, 'atm')","handlingStrategy":"validation","validationCode":"from conversions.pressure_conversions import PRESSURE_CONVERSION\n\nif from_type not in PRESSURE_CONVERSION:\n    raise ValueError(f'unsupported pressure unit {from_type!r}')\npressure_conversion(value, from_type, to_type)","typeGuard":"from conversions.pressure_conversions import PRESSURE_CONVERSION\n\ndef is_pressure_unit(u: object) -> bool:\n    return isinstance(u, str) and u in PRESSURE_CONVERSION","tryCatchPattern":"try:\n    pressure_conversion(v, f, t)\nexcept ValueError as e:\n    if \"from_type\" in str(e):\n        f = ALIASES.get(f.lower(), f)\n        result = pressure_conversion(v, f, t)\n    else:\n        raise","preventionTips":["Import PRESSURE_CONVERSION and derive dropdown options from its keys","Map user-facing units (Pa, kPa, mmHg) to library tokens at your boundary","Remember 'mmHg' == 'torr' numerically"],"tags":["python","validation","units","pressure","conversion"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}