Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 15, 2024
1 parent 4b2ec6a commit eeb87b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion mesa/experimental/mesa_signals/mesa_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ def __set__(self, instance: HasObservables, value: Computed): # noqa D103
setattr(instance, self.private_name, value)
value.name = self.public_name
value.owner = instance
getattr(instance, self.public_name) # force evaluation of the computed to build the dependency graph
getattr(
instance, self.public_name
) # force evaluation of the computed to build the dependency graph


class Computed:
Expand Down
7 changes: 5 additions & 2 deletions tests/test_mesa_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class MyAgent(Agent, HasObservables):
def __init__(self, model, value):
super().__init__(model)
self.some_other_attribute = value
self.some_attribute = Computed(lambda x: x.some_other_attribute*2, self)
self.some_attribute = Computed(lambda x: x.some_other_attribute * 2, self)

model = Model(seed=42)
agent = MyAgent(model, 10)
Expand All @@ -262,7 +262,9 @@ def __init__(self, model, value):

handler = Mock()
agent.observe("some_attribute", "change", handler)
assert agent.some_attribute == 18 # this forces a re-evaluation of the value of computed
assert (
agent.some_attribute == 18
) # this forces a re-evaluation of the value of computed
handler.assert_called_once() # and so, our change handler should be called
agent.unobserve("some_attribute", "change", handler)

Expand All @@ -271,6 +273,7 @@ def computed_func(agent):
# this creates a cyclical dependency
# our computed is dependent on o1, but also modifies o1
agent.o1 = agent.o1 - 1

class MyAgent(Agent, HasObservables):
c1 = Computable()
o1 = Observable()
Expand Down

0 comments on commit eeb87b2

Please sign in to comment.