{"record":{"id":"ec6de7093a413d02","repo":"jax-ml/jax","slug":"new-string-config-value-must-be-of-type-str-got","errorCode":null,"errorMessage":"new string config value must be of type str, got {new_val} of type {type(new_val)}.","messagePattern":"new string config value must be of type str, got (.+?) of type (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":814,"sourceCode":"    default: string, a default value for the option.\n    help: string, used to populate the flag help information as well as the\n      docstring of the returned context manager.\n    update_global_hook: an optional callback that is called with the updated\n      value of the global state when it is altered or set initially.\n    update_thread_local_hook: an optional callback that is called with the\n      updated value of the thread-local state when it is altered or set\n      initially.\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\n  def validator(new_val):\n    if not isinstance(new_val, str):\n      raise TypeError('new string config value must be of type str,'\n                       f' got {new_val} of type {type(new_val)}.')\n\n  return string_or_object_state(\n      name, default, help,\n      update_global_hook=update_global_hook,\n      update_thread_local_hook=update_thread_local_hook,\n      validator=validator)\n\n\ndef optional_string_state(\n    name: str,\n    default: str | None,\n    help: str,\n    *,\n    update_global_hook: Callable[[str], None] | None = None,\n    update_thread_local_hook: Callable[[str | None], None] | None = None,\n    include_in_trace_context: bool = False,\n) -> State[str | None]:","sourceCodeStart":796,"sourceCodeEnd":832,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L796-L832","documentation":"The validator inside string_state (invoked by the flag's parser when a value is set) requires new values to be str. Non-str values (Path, bytes, Enum, None) raise this TypeError.","triggerScenarios":"with my_flag(Path('/tmp')): or jax.config.update('jax_my_flag', SomeEnum.FOO).","commonSituations":"Passing pathlib.Path objects or Enum members to a string config flag, common in path-handling or plugin-selection code.","solutions":["Convert with str(value) before setting","For Enum, pass SomeEnum.FOO.value"],"exampleFix":"// before\nwith jax.my_flag(BASE_DIR / 'cache'):\n    ...\n// after\nwith jax.my_flag(str(BASE_DIR / 'cache')):\n    ...","handlingStrategy":"validation","validationCode":"if not isinstance(new_val, str):\n    new_val = str(new_val)","typeGuard":"def as_str(v) -> str:\n    return v if isinstance(v, str) else str(v)","tryCatchPattern":"try:\n    with my_flag(v):\n        ...\nexcept TypeError:\n    with my_flag(str(v)):\n        ...","preventionTips":["Convert Path and Enum (.value) objects before passing to string flags","Keep a thin wrapper for flag setting that enforces str types"],"tags":["jax","config","typeerror","string"],"backgroundTag":"invalid-config-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}