{"record":{"id":"8334e7fa4c3114e3","repo":"jax-ml/jax","slug":"new-int-config-value-must-be-none-or-of-type-int","errorCode":null,"errorMessage":"new int config value must be None or of type int, got {new_val} of type {type(new_val)}","messagePattern":"new int config value must be None or of type int, got (.+?) of type (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":716,"sourceCode":"\n  Returns:\n    A contextmanager to control the thread-local state value.\n  \"\"\"\n  if not isinstance(default, int):\n    raise TypeError(f\"Default value must be of type int, got {default} \"\n                    f\"of type {getattr(type(default), '__name__', type(default))}\")\n  name = name.lower()\n  default_env = os.getenv(name.upper())\n  if default_env is not None:\n    try:\n      default = int(default_env)\n    except ValueError:\n      raise ValueError(f\"Invalid value \\\"{default_env}\\\" for JAX flag {name}\")\n  config._contextmanager_flags.add(name)\n\n  def parser(new_val):\n    if new_val is not None and not isinstance(new_val, int):\n      raise ValueError(f'new int config value must be None or of type int, '\n                       f'got {new_val} of type {type(new_val)}')\n    if new_val is not None and validator is not None:\n      validator(new_val)\n    return new_val\n\n  s = State[int](name, default, help, update_global_hook,\n                 update_thread_local_hook, parser,\n                 include_in_jit_key=include_in_jit_key,\n                 include_in_trace_context=include_in_trace_context)\n  config.add_option(name, s, int, meta_args=[], meta_kwargs={\"help\": help})\n  setattr(Config, name, property(lambda _: s.value))\n  return s\n\n\ndef float_state(\n    name: str,\n    default: float,\n    help: str,","sourceCodeStart":698,"sourceCodeEnd":734,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L698-L734","documentation":"The parser for int_state rejects new values that are not None and not int (bool passes since bool subclasses int; str and float do not). Raised when setting the flag via context manager or config.update.","triggerScenarios":"jax.config.update('jax_my_flag', '128') or with my_flag(3.5): — string or float instead of int.","commonSituations":"Values sourced from argparse (strings), JSON/YAML configs, or user input being passed to an int-backed flag without conversion.","solutions":["Convert before setting: int(value)","Validate the raw input is an integer string early (e.g. argparse type=int)"],"exampleFix":"// before\njax.config.update('jax_my_flag', args.limit)  # argparse str\n// after\njax.config.update('jax_my_flag', int(args.limit))","handlingStrategy":"validation","validationCode":"if new_val is not None and (isinstance(new_val, bool) or not isinstance(new_val, int)):\n    raise ValueError(f'expected int or None, got {type(new_val)}')","typeGuard":"def is_int_or_none(v) -> bool:\n    return v is None or (isinstance(v, int) and not isinstance(v, bool))","tryCatchPattern":"try:\n    jax.config.update('jax_my_flag', val)\nexcept ValueError:\n    jax.config.update('jax_my_flag', int(val))","preventionTips":["Use argparse type=int for CLI values destined for int flags","Convert strings from JSON/YAML with int() before config.update"],"tags":["jax","config","valueerror","int"],"backgroundTag":"invalid-config-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}