{"record":{"id":"ba14abad631942b4","repo":"RustPython/RustPython","slug":"unsupported-format-format-r","errorCode":null,"errorMessage":"Unsupported format {format!r}","messagePattern":"Unsupported format (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Lib/annotationlib.py","lineNumber":1021,"sourceCode":"            ann = _get_and_call_annotate(obj, format)\n            if ann is None:\n                # If that didn't work either, we have a very weird object: evaluating\n                # __annotations__ threw NameError and there is no __annotate__. In that case,\n                # we fall back to trying __annotations__ again.\n                ann = _get_dunder_annotations(obj)\n        case Format.STRING:\n            # For STRING, we try to call __annotate__\n            ann = _get_and_call_annotate(obj, format)\n            if ann is not None:\n                return dict(ann)\n            # But if we didn't get it, we use __annotations__ instead.\n            ann = _get_dunder_annotations(obj)\n            if ann is not None:\n                return annotations_to_string(ann)\n        case Format.VALUE_WITH_FAKE_GLOBALS:\n            raise ValueError(\"The VALUE_WITH_FAKE_GLOBALS format is for internal use only\")\n        case _:\n            raise ValueError(f\"Unsupported format {format!r}\")\n\n    if ann is None:\n        if isinstance(obj, type) or callable(obj):\n            return {}\n        raise TypeError(f\"{obj!r} does not have annotations\")\n\n    if not ann:\n        return {}\n\n    if not eval_str:\n        return dict(ann)\n\n    if globals is None or locals is None:\n        if isinstance(obj, type):\n            # class\n            obj_globals = None\n            module_name = getattr(obj, \"__module__\", None)\n            if module_name:","sourceCodeStart":1003,"sourceCodeEnd":1039,"githubUrl":"https://github.com/RustPython/RustPython/blob/aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd/Lib/annotationlib.py#L1003-L1039","documentation":"The final `case _` arm of get_annotations()'s format match raises ValueError(f\"Unsupported format {format!r}\") for any value that is not one of the known Format members. Unlike the sibling 'Invalid format' error in call_annotate_function, this one guards the public get_annotations dispatch.","triggerScenarios":"`get_annotations(obj, format=99)`, `format='VALUE'`, or format=None passed positionally by mistake.","commonSituations":"Passing a string name instead of the enum; sending format over the wire as an int and deserializing without validation; stale constants from an older Python where enum members differed.","solutions":["Import and pass the enum: from annotationlib import Format; get_annotations(obj, format=Format.FORWARDREF)","Coerce with Format.try_value(value) before calling, so invalid values fail with your own handling","If format arrives as text, map it explicitly: {'value': Format.VALUE, 'string': Format.STRING, 'forwardref': Format.FORWARDREF}"],"exampleFix":"# before\nann = get_annotations(func, format='VALUE')  # ValueError\n\n# after\nfrom annotationlib import Format, get_annotations\nann = get_annotations(func, format=Format.VALUE)","handlingStrategy":"validation","validationCode":"from annotationlib import Format\n\nFORMAT_ALIASES = {'value': Format.VALUE, 'string': Format.STRING, 'forwardref': Format.FORWARDREF}\n\ndef coerce_format(raw):\n    fmt = FORMAT_ALIASES.get(str(raw).lower()) if isinstance(raw, str) else raw\n    try:\n        return Format.try_value(fmt)\n    except (ValueError, TypeError):\n        raise ValueError(f'unsupported format {raw!r}') from None","typeGuard":"from annotationlib import Format\n\ndef is_supported_format(value) -> bool:\n    return value in (Format.VALUE, Format.STRING, Format.FORWARDREF)","tryCatchPattern":null,"preventionTips":["Pass Format enum members instead of strings or raw ints","Validate format at config/CLI parse time with Format.try_value","Keep a single module-level alias map if formats arrive as text"],"tags":["annotations","annotationlib","format","valueerror","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd","analyzedAt":"2026-08-17T00:37:52.100Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}