{"record":{"id":"27a69914bdebc1d6","repo":"jax-ml/jax","slug":"expected-strategy-to-be-indexingstrategy-got-str","errorCode":null,"errorMessage":"Expected strategy to be IndexingStrategy; got {strategy}","messagePattern":"Expected strategy to be IndexingStrategy; got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/indexing.py","lineNumber":1102,"sourceCode":"\ndef rewriting_take(\n    arr: Array,\n    idx: Index | tuple[Index, ...], *,\n    indices_are_sorted: bool = False,\n    unique_indices: bool = False,\n    mode: str | slicing.GatherScatterMode | None = None,\n    fill_value: ArrayLike | None = None,\n    normalize_indices: bool = True,\n    out_sharding: NamedSharding | PartitionSpec | None = None,\n    strategy: IndexingStrategy = IndexingStrategy.AUTO,\n) -> Array:\n  # Computes arr[idx].\n  # All supported cases of indexing can be implemented as an XLA gather,\n  # followed by an optional reverse and broadcast_in_dim.\n  indexer = NDIndexer.from_raw_indices(idx, arr.shape)\n\n  if not isinstance(strategy, IndexingStrategy):\n    raise TypeError(f\"Expected strategy to be IndexingStrategy; got {strategy}\")\n\n  if config.check_static_indices.value and (mode is None or slicing.GatherScatterMode.from_any(mode) == slicing.GatherScatterMode.PROMISE_IN_BOUNDS):\n    indexer.validate_static_indices(normalize_indices=normalize_indices)\n\n  if strategy == IndexingStrategy.STATIC_SLICE:\n    static_slice_indexer = indexer.to_static_slice(\n      arr_is_sharded=indexer.is_sharded(arr),\n      normalize_indices=normalize_indices,\n      mode=mode)\n    return _static_slice(arr, static_slice_indexer)\n\n  if strategy == IndexingStrategy.DYNAMIC_SLICE:\n    dynamic_slice_indexer = indexer.to_dynamic_slice(\n      arr_is_sharded=indexer.is_sharded(arr),\n      normalize_indices=normalize_indices,\n      mode=mode)\n    return _dynamic_slice(arr, dynamic_slice_indexer)\n","sourceCodeStart":1084,"sourceCodeEnd":1120,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L1084-L1120","documentation":"Internal guard in rewriting_take: the strategy argument must be an instance of IndexingStrategy (STATIC_SLICE, DYNAMIC_SLICE, etc.). Passing anything else is an API-contract violation, usually from internal misuse or monkeypatching.","triggerScenarios":"Calling the internal rewriting_take(arr, idx, strategy=...) with a string, None, or custom object instead of an IndexingStrategy enum member.","commonSituations":"Code poking at JAX internals; stale third-party code built against an older internal API; test helpers passing raw strings.","solutions":["Pass an IndexingStrategy member, e.g. jax._src.numpy.indexing.IndexingStrategy.STATIC_SLICE","Prefer public APIs (x[idx], x.at[idx]) instead of rewriting_take"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"from jax._src.numpy.indexing import IndexingStrategy\nassert isinstance(strategy, IndexingStrategy)","typeGuard":"def is_indexing_strategy(s) -> bool:\n    from jax._src.numpy.indexing import IndexingStrategy\n    return isinstance(s, IndexingStrategy)","tryCatchPattern":null,"preventionTips":["Use public indexing APIs (x[idx], x.at[idx]) instead of internals","Pass IndexingStrategy enum members, not strings"],"tags":["jax","internal","indexing-strategy","type-error"],"backgroundTag":"internal-api-misuse","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}