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 Sep 22, 2024
1 parent 79f99a1 commit 65d4974
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion mesa/experimental/signals/code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def load_ipython_extension(ipython):
ipython : IPython.core.interactiveshell.InteractiveShell
The IPython shell instance.
"""
from ._cellmagic import load_ipython_extension # noqa: PLC0415
from ._cellmagic import load_ipython_extension

load_ipython_extension(ipython)
8 changes: 4 additions & 4 deletions mesa/experimental/signals/code/_cellmagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run_ast_nodes(
user_ns : dict
The user namespace.
Returns
Returns:
-------
dict
A dictionary with the value of the last expression in the cell.
Expand Down Expand Up @@ -86,11 +86,11 @@ def run_cell():

def prepare_cell_execution_ipywidgets(shell: InteractiveShell, raw_code: str):
try:
import ipywidgets # noqa: PLC0415
import ipywidgets
except ImportError:
raise ImportError("ipywidgets is required for this feature.") # noqa: B904

import ipywidgets # noqa: PLC0415
import ipywidgets

output_widget = ipywidgets.Output()
display(output_widget)
Expand Down Expand Up @@ -148,7 +148,7 @@ def effect(self, line, cell):
EFFECTS[name] = cleanup

@cell_magic
def clear_effects(self, line, cell): # noqa: PLR6301
def clear_effects(self, line, cell):
"""Clear all effects."""
for cleanup in EFFECTS.values():
cleanup()
Expand Down
18 changes: 9 additions & 9 deletions mesa/experimental/signals/code/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def batch(fn: typing.Callable[[], T]) -> T:
fn : Callable[[], T]
The callback function to execute within the batch.
Returns
Returns:
-------
T
The value returned by the callback function.
Expand Down Expand Up @@ -139,7 +139,7 @@ def subscribe(
fn : Callable[[T], None]
The callback function to run when the signal changes.
Returns
Returns:
-------
Callable[[], None]
A function for unsubscribing from the signal.
Expand Down Expand Up @@ -253,7 +253,7 @@ def get(self) -> T:

return value

def set(self, value: T) -> None: # noqa: PLR6301
def set(self, value: T) -> None:
raise AttributeError("Computed singals are read-only")

# def __repr__(self) -> str:
Expand All @@ -271,7 +271,7 @@ def computed(fn: typing.Callable[[], T]) -> Computed[T]:
fn : Callable[[], T]
The function to compute the value of the signal.
Returns
Returns:
-------
Computed[T]
A new read-only signal.
Expand Down Expand Up @@ -338,7 +338,7 @@ def _effect(fn: typing.Callable[[], None]) -> Disposer:
fn : Callable[[], None]
The effect callback.
Returns
Returns:
-------
Callable[[], None]
A function for disposing the effect.
Expand All @@ -365,7 +365,7 @@ def effect( # noqa: D418
Defer the effect until the next change, rather than running immediately.
By default, False.
Returns
Returns:
-------
Callable[[Callable[..., None]], Disposer]
A decorator function for creating effects.
Expand All @@ -388,7 +388,7 @@ def effect(fn: typing.Callable[[], None], /) -> Disposer: # noqa: D418
fn : Callable[[], None]
The effect callback.
Returns
Returns:
-------
Callable[[], None]
A function for disposing the effect.
Expand Down Expand Up @@ -421,7 +421,7 @@ def on(deps: typing.Sequence[Signal], *, defer: bool = False):
Defer the effect until the next change, rather than running immediately.
By default, False.
Returns
Returns:
-------
Callable[[Callable[..., None]], Callable[[], None]]
A callback function that can be registered as an effect.
Expand All @@ -445,6 +445,6 @@ def void():

func = void

return lambda: func() # noqa: PLW0108
return lambda: func()

return decorator
5 changes: 2 additions & 3 deletions mesa/experimental/signals/code/test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

from _core import Signal, Computed
from _core import Computed, Signal

a = Signal(2)
b = Signal(3)

c = Computed(lambda: a() + b())

c()
a.set(5)
a.set(5)
12 changes: 7 additions & 5 deletions mesa/experimental/signals/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def __init__(self, callable: Callable, *args, **kwargs):

# fixme this is not correct, our HasObservable might have disappeared....
# so we need to use weakrefs here.
self.parents: weakref.WeakKeyDictionary[HasObservables, dict[str], Any] = weakref.WeakKeyDictionary()
self.parents: weakref.WeakKeyDictionary[HasObservables, dict[str], Any] = (
weakref.WeakKeyDictionary()
)

def _set_dirty(self, signal):
self._is_dirty = True
Expand Down Expand Up @@ -263,10 +265,10 @@ def register_observable(cls, observable: BaseObservable):
cls.observables[observable.public_name] = observable

def observe(
self,
name: str | All,
signal_type: str | All,
handler: Callable,
self,
name: str | All,
signal_type: str | All,
handler: Callable,
):
"""Subscribe to the Observable <name> for signal_type.
Expand Down

0 comments on commit 65d4974

Please sign in to comment.