{"record":{"id":"efd2af6795ea2ff5","repo":"TheAlgorithms/Python","slug":"invalid-to-type-value-to-type-r-supported-v","errorCode":null,"errorMessage":"Invalid 'to_type' value: {to_type!r}.  Supported values are:\n{', '.join(PRESSURE_CONVERSION)}","messagePattern":"Invalid 'to_type' value: (.+?)\\.  Supported values are:\n(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"conversions/pressure_conversions.py","lineNumber":73,"sourceCode":"    >>> 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\n    doctest.testmod()\r\n","sourceCodeStart":55,"sourceCodeEnd":88,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/pressure_conversions.py#L55-L88","documentation":"Raised by pressure_conversion() in conversions/pressure_conversions.py when to_type is not a key in PRESSURE_CONVERSION (checked after from_type passes). Supported target units are the same set: atm, pascal, bar, kilopascal, megapascal, psi, inHg, torr. The ValueError message lists every valid value.","triggerScenarios":"Calling pressure_conversion(1, 'atm', 'mmHg') or pressure_conversion(1, 'atm', 'Bar') — any destination unit misspelled, wrong-cased, or unsupported such as 'mmHg'.","commonSituations":"Hardcoding a display unit string in a UI that drifted from this library's vocabulary; serializing units through a case-transforming layer (title-casing 'inHg' to 'Inhg'); supporting a unit in your product that this library simply lacks.","solutions":["Use an exact supported key for to_type (atm, pascal, bar, kilopascal, megapascal, psi, inHg, torr).","Keep a single constant tuple of valid units shared by your UI dropdown and the conversion call so they cannot drift.","Map 'mmHg' -> 'torr' (numerically identical) if mercury units are required."],"exampleFix":"# before\npressure_conversion(1, 'atm', 'mmHg')  # ValueError: Invalid 'to_type' value: 'mmHg'\n\n# after\npressure_conversion(1, 'atm', 'torr')  # 0.76 (1 mmHg == 1 torr)","handlingStrategy":"validation","validationCode":"from conversions.pressure_conversions import PRESSURE_CONVERSION\n\nif to_type not in PRESSURE_CONVERSION:\n    raise ValueError(f'unsupported target unit {to_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 \"to_type\" in str(e):\n        raise UserInputError(f'unknown target unit {t!r}') from e\n    raise","preventionTips":["Share one constant list of units between UI and converter calls","Case-sensitive matching: 'inHg' not 'inhg'","Do not title-case units when rendering labels"],"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"}