jax-ml/jax · error · TypeError
Default value must be of type int, got {default} of type {ge
Error message
Default value must be of type int, got {default} of type {getattr(type(default), '__name__', type(default))} What it means
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.
Source
Thrown at jax/_src/config.py:703
validator: Callable[[Any], None] | None = None,
) -> State[int]:
"""Set up thread-local state and return a contextmanager for managing it.
See docstring for ``bool_state``.
Args:
name: string, converted to lowercase to define the name of the config
option (and absl flag). It is converted to uppercase to define the
corresponding shell environment variable.
default: optional int, default value.
help: string, used to populate the flag help information as well as the
docstring of the returned context manager.
Returns:
A contextmanager to control the thread-local state value.
"""
if not isinstance(default, int):
raise TypeError(f"Default value must be of type int, got {default} "
f"of type {getattr(type(default), '__name__', type(default))}")
name = name.lower()
default_env = os.getenv(name.upper())
if default_env is not None:
try:
default = int(default_env)
except ValueError:
raise ValueError(f"Invalid value \"{default_env}\" for JAX flag {name}")
config._contextmanager_flags.add(name)
def parser(new_val):
if new_val is not None and not isinstance(new_val, int):
raise ValueError(f'new int config value must be None or of type int, '
f'got {new_val} of type {type(new_val)}')
if new_val is not None and validator is not None:
validator(new_val)
return new_val
View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Pass a literal int: default=10
- Convert env/file values: default=int(raw_value) before calling int_state
Example fix
// before
config.int_state('my_flag', default='10')
// after
config.int_state('my_flag', default=10) Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(default, int) and not isinstance(default, bool)
Type guard
def is_plain_int(v) -> bool:
return isinstance(v, int) and not isinstance(v, bool) Prevention
- Write int literals in defaults; convert file/env values with int() first
- Beware bool silently passing the isinstance(int) check
When it happens
Trigger: Calling config.int_state('my_flag', default='10') or default=10.5.
Common situations: Defining size/limit flags (cache sizes, retry counts) where the default comes from a string config file and is not converted to int.
Related errors
- bool() not supported for instances of type '{0}' (did you me
- Default value must be of type bool, got {default} of type {g
- Default value must be of type str, got {default} of type {ge
- Default value must be of type str or None, got {default} of
- Default value must be of type {enum_class}, got {default} of
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/9b33e35b47c4c631.
Report an issue: GitHub.