-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b213c5
commit 6136b11
Showing
3 changed files
with
16 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
from typing import Callable | ||
from functools import wraps | ||
from typing import Callable | ||
|
||
from exchange.observers.base import ObserverManager | ||
|
||
def observe_wrapper(*args, **kwargs) -> Callable: | ||
|
||
def observe_wrapper(*args, **kwargs) -> Callable: # noqa: ANN002, ANN003 | ||
"""Decorator to wrap a function with all registered observer plugins, dynamically fetched.""" | ||
def wrapper(func): | ||
|
||
def wrapper(func: Callable) -> Callable: | ||
@wraps(func) | ||
def dynamic_wrapped(*func_args, **func_kwargs): | ||
def dynamic_wrapped(*func_args, **func_kwargs) -> Callable: # noqa: ANN002, ANN003 | ||
wrapped = func | ||
for observer in ObserverManager.get_instance()._observers: | ||
wrapped = observer.observe_wrapper(*args, **kwargs)(wrapped) | ||
return wrapped(*func_args, **func_kwargs) | ||
|
||
return dynamic_wrapped | ||
return wrapper | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters