def METHOD_NAME(
    cls, val: Union[Literal["bitcode", "text", "module"], QirFormat]
) -> QirFormat:
    """
    Given a value, returns a value ensured to be of type `QirFormat`,
    attempting to convert if needed.
    """
    if isinstance(val, cls):
        return val
    elif isinstance(val, str):
        return cls[val.upper()]
    return cls(val)