{"record":{"id":"087aa58363dedcf5","repo":"jax-ml/jax","slug":"dtype-cannot-be-none","errorCode":null,"errorMessage":"dtype cannot be None.","messagePattern":"dtype cannot be None\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/dtypes.py","lineNumber":287,"sourceCode":"  elif issubdtype(obj, extended):\n    return obj  # pyrefly: ignore[bad-return]\n  elif isinstance(obj, type) and (f := _DEFAULT_TYPEMAP.get(obj)) is not None:\n    obj = f()\n  return np.dtype(obj, align=align, copy=copy)\n\n_DEFAULT_TYPEMAP: dict[type, Callable[[], np.dtype]] = {\n  bool: lambda: np.dtype(bool),\n  int: default_int_dtype,\n  float: default_float_dtype,\n  complex: default_complex_dtype,\n}\n\ndef itemsize_bits(dtype: DTypeLike) -> int:\n  \"\"\"Number of bits per element for the dtype.\"\"\"\n  # Note: we cannot use dtype.itemsize here because this is\n  # incorrect for sub-byte integer types.\n  if dtype is None:\n    raise ValueError(\"dtype cannot be None.\")\n  if dtype == np.dtype(bool):\n    return 8  # physical bit layout for boolean dtype\n  elif issubdtype(dtype, np.integer):\n    return iinfo(dtype).bits\n  elif issubdtype(dtype, np.floating):\n    return finfo(dtype).bits\n  elif issubdtype(dtype, np.complexfloating):\n    return 2 * finfo(dtype).bits\n  else:\n    raise ValueError(f\"unexpected input: {dtype=}\")\n\n# Trivial vectorspace datatype needed for tangent values of int/bool primals\nfloat0: np.dtype = np.dtype([('float0', np.void, 0)])\n\n_dtype_to_32bit_dtype: dict[DType, DType] = {\n    np.dtype('int64'): np.dtype('int32'),\n    np.dtype('uint64'): np.dtype('uint32'),\n    np.dtype('float64'): np.dtype('float32'),","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dtypes.py#L269-L305","documentation":"jax.dtypes.itemsize_bits requires a concrete dtype; passing None (typically a dtype field that was never populated) is rejected because there is no meaningful bit width.","triggerScenarios":"Calling itemsize_bits(None) or threading a None dtype from config/shape-rule code (e.g. bitcast_convert_type with unset dtype) into this helper.","commonSituations":"Optional dtype parameters defaulting to None; partially-initialized dtypes in custom primitives or sharding rules calling _bitcast paths.","solutions":["Populate the dtype before the call (resolve defaults: `dtype = dtype or jnp.float32` if that is intended)","Add an assert dtype is not None upstream to fail fast with context","Fix the caller that dropped the dtype argument"],"exampleFix":"# before\nitemsize_bits(x.dtype)  # x.dtype is None\n\n# after\nassert x.dtype is not None\nitemsize_bits(x.dtype)","handlingStrategy":"validation","validationCode":"if dtype is None:\n    raise ValueError('dtype required')\njax.dtypes.itemsize_bits(dtype)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Assert dtype is not None right after parsing inputs","Never default dtype arguments to None for numeric layout APIs"],"tags":["jax","dtype","none-guard","validation"],"backgroundTag":"none-value-validation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}