{"record":{"id":"6895fbdc8ddf6a09","repo":"jax-ml/jax","slug":"default-value-must-be-of-type-enum-class-got-d","errorCode":null,"errorMessage":"Default value must be of type {enum_class}, got {default} of type {getattr(type(default), '__name__', type(default))}","messagePattern":"Default value must be of type (.+?), got (.+?) of type (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":632,"sourceCode":"    name: string, converted to lowercase to define the name of the config\n      option (and absl flag). It is converted to uppercase to define the\n      corresponding shell environment variable.\n    enum_class: a subtype of enum.Enum.\n    default: an instance of enum_class that is the default value.\n    help: string, used to populate the flag help information as well as the\n      docstring of the returned context manager.\n    include_in_jit_key: bool, optional: whether to include the state in the\n      JIT cache key.\n    include_in_trace_context: bool, optional: whether to include the state in\n      the trace context.\n    extra_validator: optional function to validate the value of the config\n      option.\n\n  Returns:\n    A contextmanager to control the thread-local state value.\n  \"\"\"\n  if not isinstance(default, enum_class):\n    raise TypeError(\n        f'Default value must be of type {enum_class}, got {default} '\n        f\"of type {getattr(type(default), '__name__', type(default))}\"\n    )\n  name = name.lower()\n  default_str = os.getenv(name.upper(), None)\n  if default_str is not None:\n    try:\n      default = enum_class(default_str)\n    except ValueError as e:\n      raise ValueError(f\"Invalid value \\\"{default_str}\\\" for JAX flag {name}\") from e\n  config._contextmanager_flags.add(name)\n\n  def parser(new_val):\n    if isinstance(new_val, str):\n      return enum_class(new_val)\n    if not isinstance(new_val, enum_class):\n      raise TypeError(\n          f'new enum value must be an instance of {enum_class}, got'","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L614-L650","documentation":"enum_class_state requires `default` to be an instance of the given enum_class (not a raw string). Passing a string or other object raises this TypeError at flag definition.","triggerScenarios":"Calling config.enum_class_state('my_flag', enum_class=MyEnum, default='foo') instead of default=MyEnum.FOO.","commonSituations":"Migrating a flag from enum_state (string-based) to enum_class_state and forgetting to convert the default to an Enum member.","solutions":["Pass an Enum member: default=MyEnum.FOO","For string defaults, keep using enum_state instead"],"exampleFix":"// before\nconfig.enum_class_state('my_flag', enum_class=MyEnum, default='foo')\n// after\nconfig.enum_class_state('my_flag', enum_class=MyEnum, default=MyEnum.FOO)","handlingStrategy":"type-guard","validationCode":"assert isinstance(default, enum_class)","typeGuard":"import enum\ndef is_enum_member(v, cls) -> bool:\n    return isinstance(v, cls) and type(v) is not str","tryCatchPattern":null,"preventionTips":["Pass MyEnum.FOO, not 'foo', when using enum_class_state","Add a unit test that constructs every custom flag to catch definition-time errors"],"tags":["jax","config","typeerror","enum"],"backgroundTag":"invalid-config-default-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}