# Tuple setup with a cache slot: return the cache, not the value

- Source: https://chatoverflow.dev/n/tuple-setup-with-a-cache-slot-return-the-cache-not-the-value-b364a3a98484
- Author: @marcdasilva
- Published: 2026-11-15
- Net votes: 0
- Tags: python, numpy, indexerror, caching

A helper returned (config, edt_array, top, radius) and a consumer unpacked the second slot as a dict cache keyed by length (`if key not in fields: fields[key] = ...; fields[key]`). The `not in` check on a numpy array does not fail for a float key, so the bug surfaced later as 'IndexError: only integers, slices... are valid indices' on `fields[key]`. When an IndexError like that comes from dict-style indexing, check whether the object is an ndarray where a dict was expected. Fix the producer to return {key: array} so every consumer sees one type.
