{"record":{"id":"0fc93b761f1f41c0","repo":"jax-ml/jax","slug":"context-manager-for-state-name-config-option","errorCode":null,"errorMessage":"Context manager for {state.__name__} config option requires an argument representing the new value for the config option.","messagePattern":"Context manager for (.+?) config option requires an argument representing the new value for the config option\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":301,"sourceCode":"    Used to avoid cyclic import dependencies.\"\"\"\n    self._update_thread_local_hook = update_thread_local_hook\n    self._update_global_hook = update_global_hook\n    update_global_hook(self.get_global())\n\n\nclass StateContextManager[FuncType: Callable[..., Any]]:\n  __slots__ = ['state', 'new_val', 'prev']\n\n  def __init__(self, state, new_val):\n    self.state = state\n\n    if new_val is no_default:\n      if state._default_context_manager_value is not no_default:\n        new_val = state._default_context_manager_value  # default_context_manager_value provided to constructor\n      else:\n        # no default_value provided to constructor and no value provided as an\n        # argument, so we raise an error\n        raise TypeError(f\"Context manager for {state.__name__} config option \"\n                        \"requires an argument representing the new value for \"\n                        \"the config option.\")\n    if state._parser:\n      self.new_val = state._parser(new_val)\n    else:\n      self.new_val = new_val\n\n  def __enter__(self):\n    self.prev = self.state.swap_local(self.new_val)\n    if self.state._update_thread_local_hook:\n      self.state._update_thread_local_hook(self.new_val)\n\n  def __exit__(self, exc_type, exc_value, traceback):\n    self.state.set_local(self.prev)\n    if self.state._update_thread_local_hook:\n      if self.prev is config_ext.unset:\n        self.state._update_thread_local_hook(None)\n      else:","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L283-L319","documentation":"Context managers generated for config options require the new value as an argument (e.g. jax.config.enable_x64(True) style, or with_x64(True)) unless the option was defined with a default_context_manager_value. If neither an argument nor a constructor default exists, __init__ raises TypeError immediately rather than silently using the current value.","triggerScenarios":"Calling a config context manager with no argument: jax.config.some_context_manager() where some_context_manager was defined without default_context_manager_value. Options with defaults (like jax.debug_nans()) work argumentless; ones without do not.","commonSituations":"Assuming all config context managers are zero-argument toggles; calling with_x64() expecting it to default to True.","solutions":["Pass the new value explicitly: jax.config.with_x64(True)","Check the option definition: only options with default_context_manager_value can be called with no args","If you own the option, provide default_context_manager_value when defining it"],"exampleFix":"# before\nwith jax.config.some_ctx():  # TypeError\n    ...\n# after\nwith jax.config.some_ctx(True):\n    ...","handlingStrategy":"validation","validationCode":"import inspect\n\ndef with_cfg(ctx_mgr, *args, **kwargs):\n    if not args and not kwargs:\n        raise TypeError(f'{ctx_mgr} requires an explicit value, e.g. {ctx_mgr}(True)')\n    return ctx_mgr(*args, **kwargs)\n\nwith with_cfg(jax.config.some_ctx, True):\n    ...","typeGuard":null,"tryCatchPattern":"try:\n    cm = jax.config.some_ctx()\nexcept TypeError as e:\n    if 'requires an argument' in str(e):\n        cm = jax.config.some_ctx(True)\n    else:\n        raise","preventionTips":["Always pass the target value to config context managers","Check the define_* call for default_context_manager_value to know if argumentless use is allowed","Standardize on explicit values in with-statements for clarity"],"tags":["jax","config","contextmanager","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}