{"record":{"id":"9860575d4a8a6b6e","repo":"jax-ml/jax","slug":"default-value-must-be-of-type-str-got-default-o","errorCode":null,"errorMessage":"Default value must be of type str, got {default} of type {getattr(type(default), '__name__', type(default))}","messagePattern":"Default value must be of type str, got (.+?) of type (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":504,"sourceCode":"  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: 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    include_in_jit_key: bool, optional: whether to include the state in the\n      JIT cache key.\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, str):\n    raise TypeError(f\"Default value must be of type str, 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 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 type(new_val) is not str or new_val not in enum_values:\n      raise ValueError(f\"new enum value must be in {enum_values}, \"\n                       f\"got {new_val} of type {type(new_val)}.\")\n    if extra_validator is not None:\n      extra_validator(new_val)\n    return new_val\n\n  s = State[str](\n      name,\n      default,","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L486-L522","documentation":"jax._src.config.enum_state requires the `default` for an enum-backed config flag to be a Python str. Any non-str default (int, Enum member, None) raises this TypeError when the flag is defined.","triggerScenarios":"Calling config.enum_state('my_flag', default=MyEnum.FOO, enum_values=['foo','bar']) — Enum members must be converted with .value; or passing an int/None default.","commonSituations":"Defining a new JAX config flag whose options are enumerated strings but reusing an enum object or numeric default from other code.","solutions":["Pass the string value: default=MyEnum.FOO.value","If you have an Enum class, prefer config.enum_class_state which accepts enum members directly"],"exampleFix":"// before\nconfig.enum_state('my_flag', default=MyEnum.FOO, enum_values=['foo','bar'])\n// after\nconfig.enum_state('my_flag', default='foo', enum_values=['foo','bar'])","handlingStrategy":"type-guard","validationCode":"assert isinstance(default, str) and default in enum_values","typeGuard":"def is_valid_enum_default(v, values) -> bool:\n    return isinstance(v, str) and v in values","tryCatchPattern":null,"preventionTips":["Keep enum_values as the single source of truth and assert defaults against it","Use MyEnum.FOO.value, never the Enum member, with enum_state"],"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"}