Skip to content

Resolve a FIXME in mesa_signals/core.py #3481

@codebreaker32

Description

@codebreaker32

I propose a 1-line fix to resolve this fixme

# fixme this makes signaling list part of computed
if CURRENT_COMPUTED is not None:
# there is a computed dependent on this Observable, so let's add
# this Observable as a parent
CURRENT_COMPUTED._add_parent(instance, self.public_name, value)

Currently, mutable lists(such as SignalingList) fail the current_val != old_val cache-invalidation check

for attr, old_val in observations.items():
current_val = getattr(parent, attr)
if current_val != old_val:
changed = True
break

because they compare the exact same memory address against itself. By explicitly passing None into the dependency graph for mutable sequences, we can fix this

    def __get__(self, instance: HasEmitters, owner):
        value = getattr(instance, self.private_name)

        if CURRENT_COMPUTED is not None:
            # Do not store mutable sequences in the computed graph.
            value = value if not isinstance(value, MutableSequence) else None
            ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions