{"record":{"id":"785dce8eacfd3ff4","repo":"jax-ml/jax","slug":"at-least-one-array-or-dtype-is-required","errorCode":null,"errorMessage":"at least one array or dtype is required","messagePattern":"at least one array or dtype is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/dtypes.py","lineNumber":1097,"sourceCode":"@overload\ndef result_type(*args: Any, return_weak_type_flag: Literal[False] = False) -> DType: ...\n\n@overload\ndef result_type(*args: Any, return_weak_type_flag: bool = False) -> DType | tuple[DType, bool]: ...\n\n@export\ndef result_type(*args: Any, return_weak_type_flag: bool = False) -> DType | tuple[DType, bool]:\n  \"\"\"Convenience function to apply JAX argument dtype promotion.\n\n  Args:\n    return_weak_type_flag : if True, then return a ``(dtype, weak_type)`` tuple.\n      If False, just return `dtype`\n\n  Returns:\n    dtype or (dtype, weak_type) depending on the value of the ``return_weak_type`` argument.\n  \"\"\"\n  if len(args) == 0:\n    raise ValueError(\"at least one array or dtype is required\")\n  dtype: DType | ExtendedDType\n  dtype, weak_type = lattice_result_type(*(default_float_dtype() if arg is None else arg for arg in args))\n  if weak_type:\n    dtype = default_types['f' if dtype in _custom_float_dtypes else dtype.kind]()\n  return (dtype, weak_type) if return_weak_type_flag else dtype\n\ndef check_and_canonicalize_user_dtype(\n    dtype, fun_name=None, *, allow_non_jax_dtypes: bool = False\n) -> DType:\n  \"\"\"Checks validity of a user-provided dtype, and returns its canonical form.\n\n  For Python scalar types this function returns the corresponding default dtype.\n  \"\"\"\n  if dtype is None:\n    raise ValueError(\"dtype must be specified.\")\n  if isinstance(dtype, Array):\n    raise ValueError(\"Passing an array as a dtype argument is no longer \"\n                     \"supported; instead of dtype=arr use dtype=arr.dtype.\")","sourceCodeStart":1079,"sourceCodeEnd":1115,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dtypes.py#L1079-L1115","documentation":"result_type computes a promoted dtype from its arguments, so at least one is required. Called with zero arguments there is nothing to promote, and the error is raised before the promotion lattice is consulted.","triggerScenarios":"jnp.result_type() with zero args, typically from *args forwarding: jnp.result_type(*dtypes) where dtypes is an empty list.","commonSituations":"Generic wrapper functions that forward a variable-length list of arrays/dtypes which can be empty; refactors where a previously required argument became optional.","solutions":["Guard the call: if not args: use a sensible default such as jnp.float32","Require at least one argument in your wrapper and raise your own descriptive error","Pass jnp.result_type(*arrays) only after checking len(arrays) > 0"],"exampleFix":"# before\ndt = jnp.result_type(*dtypes_list)  # crashes when empty\n\n# after\ndt = jnp.result_type(*dtypes_list) if dtypes_list else jnp.float32","handlingStrategy":"validation","validationCode":"if not args:\n    args = [jnp.float32]  # or raise your own error\ndt = jnp.result_type(*args)","typeGuard":"def has_result_type_args(args) -> bool:\n    return len(args) > 0","tryCatchPattern":null,"preventionTips":["Never call jnp.result_type with *empty spreads; guard *args forwarding","Unit-test wrapper functions with empty input lists"],"tags":["jax","result-type","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}