{"record":{"id":"46829c1514a494a2","repo":"jax-ml/jax","slug":"expected-kind-to-be-a-dtype-string-or-tuple-got","errorCode":null,"errorMessage":"Expected kind to be a dtype, string, or tuple; got {kind=}","messagePattern":"Expected kind to be a dtype, string, or tuple; got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/dtypes.py","lineNumber":675,"sourceCode":"    True or False\n  \"\"\"\n  the_dtype = np.dtype(dtype)\n  kind_tuple: tuple[str | DTypeLike, ...] = (\n    kind if isinstance(kind, tuple) else (kind,)\n  )\n  options: set[DType] = set()\n  for kind in kind_tuple:\n    if isinstance(kind, str) and kind in _dtype_kinds:\n      options.update(_dtype_kinds[kind])\n      continue\n    try:\n      _dtype = np.dtype(kind)\n    except TypeError as e:\n      if isinstance(kind, str):\n        raise ValueError(\n          f\"Unrecognized {kind=} expected one of {list(_dtype_kinds.keys())}, \"\n          \"or a compatible input for jnp.dtype()\")\n      raise TypeError(\n        f\"Expected kind to be a dtype, string, or tuple; got {kind=}\"\n      ) from e\n    options.add(_dtype)\n  return the_dtype in options\n\n\ndef _jax_type(dtype: DType, weak_type: bool) -> JAXType:\n  \"\"\"Return the jax type for a dtype and weak type.\"\"\"\n  if weak_type:\n    if dtype == bool:\n      return dtype\n    if dtype in _custom_float_dtypes:\n      return float\n    return type(dtype.type(0).item())\n  return dtype\n\ndef _dtype_and_weaktype(value: Any) -> tuple[DType, bool]:\n  \"\"\"Return a (dtype, weak_type) tuple for the given input.\"\"\"","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dtypes.py#L657-L693","documentation":"jax.numpy.isdtype(dtype, kind) requires `kind` to be a dtype, a string category (like 'real','numeric','signed integer'), or a (possibly nested) tuple of those. This TypeError is raised when `kind` is some other object (e.g. a list, an int, a class instance) and NumPy's np.dtype(kind) also raised TypeError. It mirrors the semantics of the NumPy NEP 49 isdtype extension.","triggerScenarios":"Calling jnp.isdtype(x.dtype, kind=[\"real\",\"complex\"]) (list instead of tuple), passing a dtype class object like kind=int32-class where np.dtype fails, or passing an arbitrary Python object as kind. Strings that fail np.dtype parsing raise ValueError (the sibling branch); this TypeError is specifically for non-str non-dtype objects.","commonSituations":"Porting NumPy code where a list was used for kind; building kind dynamically from user input that arrives as a list; passing a numpy scalar instance or a shape tuple by mistake.","solutions":["Convert the kind argument to a tuple: jnp.isdtype(dt, tuple(kinds)) if it is a list","Use one of the recognized kind strings: 'bool','signed integer','unsigned integer','integral','real floating','complex floating','numeric','real'","Pass a concrete dtype (e.g. np.dtype('float32') or jnp.float32) as kind"],"exampleFix":"# before\njnp.isdtype(x.dtype, kind=['real', 'complex'])\n\n# after\njnp.isdtype(x.dtype, kind=('real', 'complex'))","handlingStrategy":"validation","validationCode":"def valid_kind(k):\n    from jax._src import dtypes\n    allowed = {'bool','signed integer','unsigned integer','integral',\n               'real floating','complex floating','numeric','real'}\n    if isinstance(k, tuple):\n        return all(valid_kind(x) for x in k)\n    return isinstance(k, str) and k in allowed or hasattr(k, 'itemsize') or k in dtypes._dtype_kinds\nkind = tuple(kind) if isinstance(kind, list) else kind","typeGuard":"def is_isdtype_kind(k: object) -> bool:\n    if isinstance(k, tuple):\n        return all(is_isdtype_kind(x) for x in k)\n    if isinstance(k, str):\n        return k in {'bool','signed integer','unsigned integer','integral',\n                     'real floating','complex floating','numeric','real'}\n    return isinstance(k, np.dtype) or k in (bool, int, float, complex)","tryCatchPattern":null,"preventionTips":["Always pass kind as a tuple, never a list","Validate kind against the allowed category strings before calling isdtype"],"tags":["jax","dtype","isdtype","argument-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}