{"record":{"id":"76d9428f875fd365","repo":"jax-ml/jax","slug":"default-value-must-be-of-type-str-or-none-got-de","errorCode":null,"errorMessage":"Default value must be of type str or None, got {default} of type {getattr(type(default), '__name__', type(default))}","messagePattern":"Default value must be of type str or None, got (.+?) of type (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":568,"sourceCode":"  \"\"\"Set up thread-local state and return a contextmanager for managing it.\n\n  See docstring for ``bool_state``.\n\n  Args:\n    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_values: list of strings representing the possible values for the\n      option.\n    default: optional string, default value.\n    help: string, used to populate the flag help information as well as the\n      docstring of the returned context manager.\n\n  Returns:\n    A contextmanager to control the thread-local state value.\n  \"\"\"\n  if default is not None and not isinstance(default, str):\n    raise TypeError(f\"Default value must be of type str or None, got {default} \"\n                    f\"of type {getattr(type(default), '__name__', type(default))}\")\n  name = name.lower()\n  default = os.getenv(name.upper(), default)\n  if default is not None and default not in enum_values:\n    raise ValueError(f\"Invalid value \\\"{default}\\\" for JAX flag {name}\")\n  config._contextmanager_flags.add(name)\n\n  def parser(new_val):\n    if (new_val is not None and\n      (type(new_val) is not str or new_val not in enum_values)):\n      raise ValueError(f\"new enum value must be None or in {enum_values}, \"\n                       f\"got {new_val} of type {type(new_val)}.\")\n    return new_val\n\n  s = State[str | None](\n      name, default, help, update_global_hook, update_thread_local_hook,\n      parser, include_in_jit_key=include_in_jit_key,\n      include_in_trace_context=include_in_trace_context,","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L550-L586","documentation":"optional_enum_state requires `default` to be a str or None. Any other type (Enum member, int, bool) raises this TypeError at flag-definition time.","triggerScenarios":"Calling config.optional_enum_state('my_flag', default=MyEnum.FOO, enum_values=[...]) instead of default='foo' or default=None.","commonSituations":"Defining an optional enum flag (e.g. a 'not set means auto' option) and passing an enum object rather than its string value.","solutions":["Pass MyEnum.FOO.value or None","Or use enum_class_state if you want to work with Enum members"],"exampleFix":"// before\nconfig.optional_enum_state('my_flag', default=MyEnum.FOO, enum_values=['foo','bar'])\n// after\nconfig.optional_enum_state('my_flag', default=None, enum_values=['foo','bar'])","handlingStrategy":"type-guard","validationCode":"assert default is None or isinstance(default, str)","typeGuard":"def is_optional_str(v) -> bool:\n    return v is None or isinstance(v, str)","tryCatchPattern":null,"preventionTips":["Convert enum members with .value before using as defaults","Use enum_class_state when you want typed Enum values"],"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"}