jax-ml/jax · error · TypeError

bool() not supported for instances of type '{0}' (did you me

Error message

bool() not supported for instances of type '{0}' (did you mean to use '{0}.value' instead?)

What it means

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.

Source

Thrown at jax/_src/config.py:265

                     include_in_trace_context=include_in_trace_context)
    self._name = name
    self.__name__ = name[4:] if name.startswith('jax_') else name
    self.__doc__ = (f"Context manager for `{name}` config option"
                    f"{extra_description}.\n\n{help}")
    self._update_global_hook = update_global_hook
    self._update_thread_local_hook = update_thread_local_hook
    self._parser = parser
    self._default_context_manager_value = default_context_manager_value
    if self._update_global_hook:
      self._update_global_hook(default)
    config_states[name] = self

  @property
  def name(self):
    return self._name

  def __bool__(self) -> NoReturn:
    raise TypeError(
        "bool() not supported for instances of type '{0}' "
        "(did you mean to use '{0}.value' instead?)".format(
            type(self).__name__))

  def _set(self, value: _T) -> None:
    if self._parser:
      value = self._parser(value)
    self.set_global(value)
    if self._update_global_hook:
      self._update_global_hook(value)

  def __call__(self, new_val: Any = no_default):
    return StateContextManager(self, new_val)

  def _add_hooks(self, update_global_hook, update_thread_local_hook):
    """Private method that adds hooks to an existing context-manager.

    Used to avoid cyclic import dependencies."""

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Use holder.value (or jax.config.<option_name>) wherever the object was used as a bool
  2. If storing the option, store its current value: val = jax.config.jax_enable_x64
  3. Lint for `if holder:` patterns on config objects in your codebase

Example fix

# before
holder = jax.config._value_holders['jax_enable_x64']
if holder: ...
# after
if jax.config.jax_enable_x64: ...
Defensive patterns

Strategy: type-guard

Validate before calling

opt_value = jax.config.jax_enable_x64  # read the value, never the holder
assert isinstance(opt_value, bool)

Type guard

def is_config_value(v: object) -> TypeGuard[bool]:
    return isinstance(v, bool)  # values read via config.<name>, not holders

Prevention

When it happens

Trigger: 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.

Common situations: Introspection code or tests that grab holder objects from internals; refactoring where a .value accessor was dropped accidentally.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/7b1c53f702323e1f. Report an issue: GitHub.