{"record":{"id":"1d56bfdb5f492270","repo":"jax-ml/jax","slug":"self-r-has-no-shape","errorCode":null,"errorMessage":"{self!r} has no `shape`.","messagePattern":"(.+?) has no `shape`\\.","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"jax/_src/state/types.py","lineNumber":335,"sourceCode":"      if isinstance(ref, TransformedRef):\n        return ref.type\n      elif type(ref) in core.pytype_aval_mappings:\n        return core.typeof(ref)\n      else:\n        return ref\n\n    if self.multiref:\n      ref_ty = tuple(_type(r) for r in self.ref)\n      return cast(MultiRefTransform, self.transforms[0]).transform_types(ref_ty)\n    ref_ty = _type(self.ref)\n    for t in self.transforms:\n      ref_ty = t.transform_type(ref_ty)\n    return ref_ty\n\n  @property\n  def shape(self) -> tuple[int | Array, ...]:\n    if not hasattr(self.type, \"shape\"):\n      raise AttributeError(f\"{self!r} has no `shape`.\") from None\n    return self.type.shape\n\n  @property\n  def dtype(self):\n    if not hasattr(self.type, \"dtype\"):\n      raise AttributeError(f\"{self!r} has no `dtype`.\") from None\n    return self.type.dtype\n\n  ndim = property(lambda self: len(self.shape))\n  size = property(lambda self: math.prod(self.shape))\n  T = property(lambda self: self.transpose(tuple(reversed(range(self.ndim)))))\n\n  @property\n  def at(self) -> RefIndexer:\n    return RefIndexer(self)\n\n  def bitcast(self, dtype):\n    if self.is_dynamic_size:","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/state/types.py#L317-L353","documentation":"TransformedRef.shape raises AttributeError when the underlying transformed type has no shape attribute (e.g. the ref's aval isn't a ShapedArray after transforms). The 'from None' suppresses the original error chain for a cleaner message.","triggerScenarios":"Accessing .shape (or .ndim/.size which derive from it) on a ref whose transformed aval lacks a shape, such as certain memory-space or token-like avals.","commonSituations":"Generic utility code that probes .shape on arbitrary ref-like objects; refs whose inner aval is not an array.","solutions":["Guard with hasattr(ref.type, 'shape') or getattr before access","Check the ref's aval type before using shape-dependent properties","Restructure so only array-backed refs reach this code path"],"exampleFix":"// before\ns = ref.shape\n// after\ns = ref.shape if hasattr(ref.type, \"shape\") else None","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def has_shape(ref):\n    return hasattr(ref.type, \"shape\") if hasattr(ref, \"type\") else hasattr(ref, \"shape\")","tryCatchPattern":null,"preventionTips":["Probe attribute existence before shape access","Keep generic utilities duck-typing-safe"],"tags":["jax","attribute-error","shape"],"backgroundTag":"missing-attribute-access","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}