{"record":{"id":"70cb9c2088c81c9c","repo":"jax-ml/jax","slug":"default-value-must-be-of-type-float-got-default","errorCode":null,"errorMessage":"Default value must be of type float, got {default} of type {getattr(type(default), '__name__', type(default))}","messagePattern":"Default value must be of type float, got (.+?) of type (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":755,"sourceCode":"    update_thread_local_hook: Callable[[float | None], None] | None = None,\n) -> State[float]:\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: 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, float):\n    raise TypeError(f\"Default value must be of type float, 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 = float(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, (float, int)):\n      raise ValueError(\n        f'new float config value must be None or of type float, '\n        f'got {new_val} of type {type(new_val)}')\n    return new_val\n\n  s = State[float](name, default, help, update_global_hook,","sourceCodeStart":737,"sourceCodeEnd":773,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L737-L773","documentation":"float_state requires `default` to be a Python float; ints and strings are rejected (unlike the runtime parser, which accepts ints). Non-float defaults raise this TypeError at flag definition.","triggerScenarios":"Calling config.float_state('my_flag', default=1) or default='0.5'.","commonSituations":"Defining a tolerance/learning-rate style flag and naturally writing default=0 (int) instead of 0.0.","solutions":["Add a decimal point: default=0.5 or default=float(value)","Wrap externally-sourced defaults with float(...)"],"exampleFix":"// before\nconfig.float_state('my_flag', default=1)\n// after\nconfig.float_state('my_flag', default=1.0)","handlingStrategy":"type-guard","validationCode":"assert isinstance(default, float), 'default must be a Python float (write 1.0 not 1)'","typeGuard":"def is_float(v) -> bool:\n    return isinstance(v, float)","tryCatchPattern":null,"preventionTips":["Always include a decimal point in float flag defaults","Wrap dynamic defaults with float(...)"],"tags":["jax","config","typeerror","float"],"backgroundTag":"invalid-config-default-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}