Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
quaquel committed Sep 27, 2024
1 parent f0c918a commit 8afea8c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mesa/experimental/signals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Functionality for Observables."""

from .observable_collections import ObservableList
from .signal import All, Computable, Computed, HasObservables, Observable, Signal
from .mesa_signal import All, Computable, Computed, HasObservables, Observable, Signal

__all__ = [
"Observable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from collections.abc import Callable
from typing import Any

from .signals_util import create_weakref
from mesa.experimental.signals.signals_util import create_weakref

__all__ = ["Observable", "HasObservables", "All", "Computable"]

Expand Down Expand Up @@ -127,8 +127,12 @@ def __init__(self):

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

old_value = computed._value

# fixme, we are not detecting if one computable is dependent on another
if CURRENT_COMPUTED is not None:
CURRENT_COMPUTED._add_parent(instance, self.public_name, old_value)

new_value = computed()

if new_value != old_value:
Expand All @@ -151,6 +155,7 @@ def __set__(self, instance: HasObservables, value): # noqa D103
# no on change event?
setattr(instance, self.private_name, value)
value.name = self.public_name
value.owner = instance


class Computed:
Expand All @@ -162,6 +167,7 @@ def __init__(self, func: Callable, *args, **kwargs):
self._first = True
self._value = None
self.name: str = "" # set by Computable
self.owner: HasObservables # set by Computable

self.parents: weakref.WeakKeyDictionary[HasObservables, dict[str, Any]] = (
weakref.WeakKeyDictionary()
Expand Down
2 changes: 1 addition & 1 deletion mesa/experimental/signals/observable_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections.abc import Iterable, MutableSequence
from typing import Any

from .signal import BaseObservable, HasObservables
from .mesa_signal import BaseObservable, HasObservables

__all__ = [
"ObservableList",
Expand Down

0 comments on commit 8afea8c

Please sign in to comment.