Skip to content

task(underscore_args): match st.cache_data for underscore-prefixed arguments - #3

Merged
mysiar merged 2 commits into
masterfrom
underscore_args
Aug 25, 2026
Merged

task(underscore_args): match st.cache_data for underscore-prefixed arguments#3
mysiar merged 2 commits into
masterfrom
underscore_args

Conversation

@mysiar

@mysiar mysiar commented Aug 25, 2026

Copy link
Copy Markdown
Member

match st.cache_data for underscore-prefixed arguments

An argument whose parameter name starts with an underscore was only kept out of the cache key when the caller passed it by keyword. _entry_key filtered kwargs by name and hashed the args tuple whole, and a tuple carries no names, so the same argument passed positionally still landed in the key. st.cache_data resolves positional arguments to their parameter names first and skips them either way, which is what the README promises parity with.

Resolve positional slots to their parameter names through inspect.signature, once per decorated function rather than per call, and drop the underscore ones before hashing. Slots filled by *args keep being hashed: there is no name there to test. Functions with no introspectable signature fall back to hashing every positional argument.

Keying by name rather than by position also means a positional call and a keyword call with the same values now reach one entry instead of two.

Keyword order stays insensitive, which is a deliberate departure from st.cache_data: it hashes kwargs in caller order, so it treats f(a=1, b=2) and f(b=2, a=1) as separate entries. Sorting by name is the better behaviour and two existing tests already cover it.

The key payload changed, so entries written by 0.1.0 are orphaned on upgrade. Ones with a TTL expire and get swept as usual; ttl=None entries are never swept and need clear(). Minor version bump for that.

mysiar and others added 2 commits August 25, 2026 13:28
…guments

An argument whose parameter name starts with an underscore was only kept out
of the cache key when the caller passed it by keyword. _entry_key filtered
kwargs by name and hashed the args tuple whole, and a tuple carries no names,
so the same argument passed positionally still landed in the key. st.cache_data
resolves positional arguments to their parameter names first and skips them
either way, which is what the README promises parity with.

Resolve positional slots to their parameter names through inspect.signature,
once per decorated function rather than per call, and drop the underscore ones
before hashing. Slots filled by *args keep being hashed: there is no name there
to test. Functions with no introspectable signature fall back to hashing every
positional argument.

Keying by name rather than by position also means a positional call and a
keyword call with the same values now reach one entry instead of two.

Keyword order stays insensitive, which is a deliberate departure from
st.cache_data: it hashes kwargs in caller order, so it treats f(a=1, b=2) and
f(b=2, a=1) as separate entries. Sorting by name is the better behaviour and
two existing tests already cover it.

The key payload changed, so entries written by 0.1.0 are orphaned on upgrade.
Ones with a TTL expire and get swept as usual; ttl=None entries are never
swept and need clear(). Minor version bump for that.
Runs ruff and the pytest suite with coverage on every branch push, on pull
requests and on manual dispatch, across Python 3.12 and 3.13. Mirrors the
lint and tests targets in the Makefile. Concurrency group keeps one run per
ref, cancelling the run still in flight.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mysiar
mysiar merged commit d5ed39e into master Aug 25, 2026
4 checks passed
@mysiar
mysiar deleted the underscore_args branch August 25, 2026 13:37
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.

1 participant