{"record":{"id":"9b33e35b47c4c631","repo":"jax-ml/jax","slug":"default-value-must-be-of-type-int-got-default-o","errorCode":null,"errorMessage":"Default value must be of type int, got {default} of type {getattr(type(default), '__name__', type(default))}","messagePattern":"Default value must be of type int, got (.+?) of type (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":703,"sourceCode":"    validator: Callable[[Any], None] | None = None,\n) -> State[int]:\n  \"\"\"Set up thread-local state and return a contextmanager for managing it.\n\n  See docstring for ``bool_state``.\n\n  Args:\n    name: string, converted to lowercase to define the name of the config\n      option (and absl flag). It is converted to uppercase to define the\n      corresponding shell environment variable.\n    default: optional int, default value.\n    help: string, used to populate the flag help information as well as the\n      docstring of the returned context manager.\n\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","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L685-L721","documentation":"int_state requires the `default` for an integer config flag to be an int (note: bool is a subclass of int and would pass; floats and strings do not). Non-int defaults raise this TypeError at flag definition.","triggerScenarios":"Calling config.int_state('my_flag', default='10') or default=10.5.","commonSituations":"Defining size/limit flags (cache sizes, retry counts) where the default comes from a string config file and is not converted to int.","solutions":["Pass a literal int: default=10","Convert env/file values: default=int(raw_value) before calling int_state"],"exampleFix":"// before\nconfig.int_state('my_flag', default='10')\n// after\nconfig.int_state('my_flag', default=10)","handlingStrategy":"type-guard","validationCode":"assert isinstance(default, int) and not isinstance(default, bool)","typeGuard":"def is_plain_int(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool)","tryCatchPattern":null,"preventionTips":["Write int literals in defaults; convert file/env values with int() first","Beware bool silently passing the isinstance(int) check"],"tags":["jax","config","typeerror","int"],"backgroundTag":"invalid-config-default-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}