feat(tools): add cached_property_names MRO walker#111
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New public helper
autoconf.tools.decorators.cached_property_names(cls) -> frozenset[str]. Walkscls.__mro__, collects names of@functools.cached_propertyand autoconf@CachedPropertydescriptors, memoises on the class itself.Foundation for two paired PRs:
__dict__-iteration filter sites inautofit/mapper/__dict__-iteration filter sites inabstract_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 JAXjit(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
🤖 Generated with Claude Code