Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions autofit/mapper/prior_model/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,26 @@ def info(self) -> str:
"""
formatter = TextFormatter(line_length=info_whitespace())

def _excluded_by_parent(path):
# Honor each parent's `__exclude_identifier_fields__` here so attributes
# that classes have already declared "not part of the model's identity"
# (e.g. JAX pytree tokens) do not leak into the human-readable model.info.
if not path:
return False
parent = self
for step in path[:-1]:
try:
if isinstance(step, int):
parent = parent[step]
elif isinstance(parent, dict):
parent = parent[step]
else:
parent = parent.__dict__[step]
except (AttributeError, KeyError, IndexError, TypeError):
return False
excluded = getattr(type(parent), "__exclude_identifier_fields__", ())
return path[-1] in excluded

for t in find_groups(
[
t
Expand All @@ -1788,6 +1808,7 @@ def info(self) -> str:
ignore_children=True,
)
if t[0][-1] not in ("id", "item_number")
and not _excluded_by_parent(t[0])
],
limit=1,
):
Expand Down
19 changes: 19 additions & 0 deletions test_autofit/mapper/test_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,22 @@ def test_is_instance():
constant = af.Constant(1.0)

assert isinstance(constant, float)


class _ClassWithExcludedField:
# Mirrors the LightProfileLinear pattern: an internal attribute set in
# __init__ that is declared not part of the model identity. The info
# property must respect that contract and suppress `token`.
__exclude_identifier_fields__ = ("token",)

def __init__(self, value: float = 0.5):
self.value = value
self.token = 7


def test_info_honors_exclude_identifier_fields():
model = af.Collection(thing=_ClassWithExcludedField())

info = model.info
assert "token" not in info
assert "value" in info
Loading