Skip to content

fix: disallow_overwrites no-op and cache_func_outputs default/kwargs bugs - #104

Merged
thorwhalen merged 1 commit into
masterfrom
fix-101-broken-helpers
Sep 22, 2026
Merged

thorwhalen merged 1 commit into
masterfrom
fix-101-broken-helpers

Conversation

@thorwhalen

Copy link
Copy Markdown
Member

Summary

Fixes the two bugs reported in #101, both found by @thorwhalen while verifying docstring claims for the WP6 documentation sweep:

  • dol.trans.disallow_overwrites was a no-op -- it built an inner __setitem__ but never attached it and returned None. Now returns a proper subclass of store with the __setitem__ guard attached, plus (honoring disable_deletes, previously ignored entirely) an equivalent __delitem__ guard.
  • dol.caching.cache_func_outputs: with the default cache=HashableDict, get_cache returned the class rather than an instance (a class object satisfies is_a_cache's hasattr checks), so the first call raised TypeError: argument of type 'type' is not iterable. Fixed by explicitly instantiating a bare class/factory before use. Separately, kwargs were wrapped in a fresh HashableDict each call -- whose __hash__ is identity-based (id(self)) -- so kwargs-based calls never hit the cache. Now keyed on a stable, value-based tuple of sorted kwargs items.

Chose "finish" over "delete" (the issue's other offered option, and the one #94's cruft audit separately lists as a zero-fleet-usage candidate) since both are now correct and useful, and neither is part of the public dol/__init__.py surface -- so #94 can still relocate them later if fleet adoption stays at zero.

Closes #101

Review

Per the crowsnest "review before merging behaviour-changing code" policy, this was reviewed by an independent sub-agent before merge (see RUN_LOG). It confirmed both original bugs are fixed with no test regressions, and caught two follow-up issues, both fixed in this PR:

  1. The error_msg docstring claimed {k} worked as a placeholder, but the code did .format(k) (positional-only) -- {k} raised KeyError. Fixed: .format(k, k=k) supports both.
  2. Unhashable kwargs values (e.g. a list) now raise TypeError instead of silently never caching (the old HashableDict-wrapping masked this). Documented as intentional -- matches dol's own "no silent failures" convention, and the pre-existing requirement that positional args be hashable too.

Dependents checked

Neither function is exported from dol/__init__.py, and no on-box fleet package (checked all ~89 dol dependents present under /root/py/proj) imports either by name.

Test plan

  • pytest --doctest-modules dol/trans.py dol/caching.py -> 70 passed
  • pytest (full suite) -> 592 passed, 3 skipped (baseline: 590 passed, 3 skipped before this session's other dol work)

🤖 Generated with Claude Code

https://claude.ai/code/session_011HSBVhDjRU4apSLcRkavv9

…bugs

- dol.trans.disallow_overwrites: was a no-op (built an inner __setitem__
  but never attached it, returned None). Now returns a proper subclass
  of `store` with the __setitem__ guard attached, and (per the
  `disable_deletes` param, previously ignored) an equivalent __delitem__
  guard. error_msg supports both `{}` and `{k}` placeholders.

- dol.caching.cache_func_outputs: with the default `cache=HashableDict`,
  `get_cache` returned the *class* (not an instance), so the first call
  raised `TypeError: argument of type 'type' is not iterable`. Now
  explicitly instantiates a bare class/factory before use. Separately,
  kwargs were wrapped in a fresh HashableDict each call, whose __hash__
  is identity-based (id(self)) -- so kwargs-based calls never hit the
  cache. Now keys on a stable, value-based tuple of the sorted kwargs
  items instead.

Both were reported, precisely diagnosed, and left as a fix-or-delete
choice in the issue. Chose "finish" over "delete" (the issue's other
option, and the one #94's cruft audit lists as a candidate) since
they're now correct, useful, and not part of the public dol/__init__.py
API -- so #94 can still relocate them later if fleet adoption stays at
zero.

Reviewed by an independent sub-agent before merge (per crowsnest policy),
which caught two follow-up issues, both fixed here: the error_msg `{k}`
placeholder didn't actually work (positional-only .format call), and
unhashable kwargs values now raise TypeError instead of silently never
caching -- documented as intentional (dol's own "no silent failures"
convention), matching the pre-existing requirement that positional args
be hashable too.

Closes #101

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@thorwhalen
thorwhalen merged commit 90ad00a into master Sep 22, 2026
12 checks passed
@thorwhalen
thorwhalen deleted the fix-101-broken-helpers branch September 22, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two helpers that don't do what their names say: disallow_overwrites (no-op) and cache_func_outputs (default cache fails, kwargs never cached)

1 participant