/** * Replicate Python `dict.get(key, default)`: return the value when the key is * present (even if the value is null), and the default only when the key is absent. * * TS `??` is NOT equivalent — it triggers on null, so `obj.k ?? []` returns `[]` * for `{ k: null }` whereas python `d.get("k", [])` returns `null`. * * Use this anywhere a Python provider uses `dict.get(key, default)` with a * non-null default (e.g. `crate.get("categories", [])`). */ export function pyGet(obj: Record | null | undefined, key: string, def: T): T | unknown { if (obj && key in obj) return obj[key]; return def; }