Skip to content

feat(tools): add cached_property_names MRO walker#111

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/cached-property-names-helper
May 29, 2026
Merged

feat(tools): add cached_property_names MRO walker#111
Jammy2211 merged 1 commit into
mainfrom
feature/cached-property-names-helper

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

New public helper autoconf.tools.decorators.cached_property_names(cls) -> frozenset[str]. Walks cls.__mro__, collects names of @functools.cached_property and autoconf @CachedProperty descriptors, memoises on the class itself.

Foundation for two paired PRs:

  • PyAutoLabs/PyAutoFit#TBD — apply at 6 __dict__-iteration filter sites in autofit/mapper/
  • PyAutoLabs/PyAutoArray#TBD — apply at 2 __dict__-iteration filter sites in abstract_ndarray.py (pytree flatten paths)

Defends against the class of bug PyAutoFit #1300 fixed for AbstractPriorModel.parameterization: any future cached_property declared on a model or Fit class would otherwise silently leak its cached return value through every __dict__ walker and reproduce the same 38-script JAX jit(fit_from) regression.

Test plan

  • pytest test_autoconf/test_cached_property_names.py -v — 9/9 pass.
  • pytest test_autoconf -q — 111/111 pass, no regressions.

Related

  • PyAutoFit #1300 — the minimal hotfix this builds on (parameterization sidecar).

🤖 Generated with Claude Code

New public helper `autoconf.tools.decorators.cached_property_names(cls)`
walks `cls.__mro__` and returns a frozenset of every
`@functools.cached_property` and autoconf `@CachedProperty` descriptor
name. Result is memoised on the class itself under
`__cached_property_names_cache__`.

Used by PyAutoFit + PyAutoArray to extend their existing
`__dict__`-iteration filters with a forward-compatibility guard: any
future cached_property declared on a model or Fit class is
automatically excluded from instance construction, ModelInstance.dict,
pickling, and JAX pytree flattening. Defends against the class of bug
PyAutoFit #1300 fixed for `AbstractPriorModel.parameterization`.

9 unit tests cover: empty class, stdlib + autoconf descriptor
variants, MRO walk through inheritance chain, regular @Property is
ignored, memoisation lands on the class itself, subclass cache is
independent of parent cache.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit db1d135 into main May 29, 2026
6 checks passed
@Jammy2211 Jammy2211 deleted the feature/cached-property-names-helper branch May 29, 2026 07:30
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