{"record":{"id":"7b1c53f702323e1f","repo":"jax-ml/jax","slug":"bool-not-supported-for-instances-of-type-0","errorCode":null,"errorMessage":"bool() not supported for instances of type '{0}' (did you mean to use '{0}.value' instead?)","messagePattern":"bool\\(\\) not supported for instances of type '(.+?)' \\(did you mean to use '(.+?)\\.value' instead\\?\\)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":265,"sourceCode":"                     include_in_trace_context=include_in_trace_context)\n    self._name = name\n    self.__name__ = name[4:] if name.startswith('jax_') else name\n    self.__doc__ = (f\"Context manager for `{name}` config option\"\n                    f\"{extra_description}.\\n\\n{help}\")\n    self._update_global_hook = update_global_hook\n    self._update_thread_local_hook = update_thread_local_hook\n    self._parser = parser\n    self._default_context_manager_value = default_context_manager_value\n    if self._update_global_hook:\n      self._update_global_hook(default)\n    config_states[name] = self\n\n  @property\n  def name(self):\n    return self._name\n\n  def __bool__(self) -> NoReturn:\n    raise TypeError(\n        \"bool() not supported for instances of type '{0}' \"\n        \"(did you mean to use '{0}.value' instead?)\".format(\n            type(self).__name__))\n\n  def _set(self, value: _T) -> None:\n    if self._parser:\n      value = self._parser(value)\n    self.set_global(value)\n    if self._update_global_hook:\n      self._update_global_hook(value)\n\n  def __call__(self, new_val: Any = no_default):\n    return StateContextManager(self, new_val)\n\n  def _add_hooks(self, update_global_hook, update_thread_local_hook):\n    \"\"\"Private method that adds hooks to an existing context-manager.\n\n    Used to avoid cyclic import dependencies.\"\"\"","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L247-L283","documentation":"Config state holder objects implement __bool__ to raise, because a bare truthiness test like `if config.some_option:` is almost always a bug — it tests the holder object, not its value. Developers must use the .value property (or the config-level property) explicitly. The error message names the type and suggests .value.","triggerScenarios":"Holding a reference to a ConfigState/_State instance (e.g. from config._value_holders['jax_enable_x64']) and using it in a boolean context: if holder:, assert holder, or passing it to code that calls bool() on it.","commonSituations":"Introspection code or tests that grab holder objects from internals; refactoring where a .value accessor was dropped accidentally.","solutions":["Use holder.value (or jax.config.<option_name>) wherever the object was used as a bool","If storing the option, store its current value: val = jax.config.jax_enable_x64","Lint for `if holder:` patterns on config objects in your codebase"],"exampleFix":"# before\nholder = jax.config._value_holders['jax_enable_x64']\nif holder: ...\n# after\nif jax.config.jax_enable_x64: ...","handlingStrategy":"type-guard","validationCode":"opt_value = jax.config.jax_enable_x64  # read the value, never the holder\nassert isinstance(opt_value, bool)","typeGuard":"def is_config_value(v: object) -> TypeGuard[bool]:\n    return isinstance(v, bool)  # values read via config.<name>, not holders","tryCatchPattern":null,"preventionTips":["Read options via jax.config.<name> or holder.value; never use the holder as a bool","Static typing: annotate config reads as bool so accidental holder leaks fail typecheck","Avoid touching config._value_holders internals in production code"],"tags":["jax","config","typeerror","truthiness"],"backgroundTag":"invalid-truthiness-check","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}