From 65d497403eaab0d4ad8471484152910c74d0e118 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:19:59 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mesa/experimental/signals/code/__init__.py | 2 +- mesa/experimental/signals/code/_cellmagic.py | 8 ++++---- mesa/experimental/signals/code/_core.py | 18 +++++++++--------- mesa/experimental/signals/code/test.py | 5 ++--- mesa/experimental/signals/signal.py | 12 +++++++----- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/mesa/experimental/signals/code/__init__.py b/mesa/experimental/signals/code/__init__.py index b6901fef336..22e8be7b528 100644 --- a/mesa/experimental/signals/code/__init__.py +++ b/mesa/experimental/signals/code/__init__.py @@ -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) diff --git a/mesa/experimental/signals/code/_cellmagic.py b/mesa/experimental/signals/code/_cellmagic.py index da6bbc293bc..b947b1314f2 100644 --- a/mesa/experimental/signals/code/_cellmagic.py +++ b/mesa/experimental/signals/code/_cellmagic.py @@ -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. @@ -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) @@ -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() diff --git a/mesa/experimental/signals/code/_core.py b/mesa/experimental/signals/code/_core.py index eb0312ec91a..e6e0cb54c8f 100644 --- a/mesa/experimental/signals/code/_core.py +++ b/mesa/experimental/signals/code/_core.py @@ -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. @@ -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. @@ -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: @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -445,6 +445,6 @@ def void(): func = void - return lambda: func() # noqa: PLW0108 + return lambda: func() return decorator diff --git a/mesa/experimental/signals/code/test.py b/mesa/experimental/signals/code/test.py index 82e3ececd2f..3df74f21af1 100644 --- a/mesa/experimental/signals/code/test.py +++ b/mesa/experimental/signals/code/test.py @@ -1,5 +1,4 @@ - -from _core import Signal, Computed +from _core import Computed, Signal a = Signal(2) b = Signal(3) @@ -7,4 +6,4 @@ c = Computed(lambda: a() + b()) c() -a.set(5) \ No newline at end of file +a.set(5) diff --git a/mesa/experimental/signals/signal.py b/mesa/experimental/signals/signal.py index d97c1b7493f..5ba35e98795 100644 --- a/mesa/experimental/signals/signal.py +++ b/mesa/experimental/signals/signal.py @@ -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 @@ -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 for signal_type.