Expose the wrapped function in `@action`.

Added a `wrapped` "hidden" parameter to the function returned by the
`@action` decorator.

We need this to access the underlying decorated function when e.g. we
need to access its specs or decorators.
This commit is contained in:
Fabio Manganiello 2023-10-09 22:35:08 +02:00
parent 1e93af86f4
commit 52e353dc14
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
2 changed files with 5 additions and 1 deletions

View File

@ -56,6 +56,8 @@ def action(f: Callable[..., Any]) -> Callable[..., Response]:
# Propagate the docstring
_execute_action.__doc__ = f.__doc__
# Expose the wrapped function
_execute_action.wrapped = f # type: ignore
return _execute_action
@ -64,6 +66,7 @@ class Plugin(EventGenerator, ExtensionWithManifest): # lgtm [py/missing-call-to
def __init__(self, **kwargs):
super().__init__()
self.logger = logging.getLogger(
'platypush:plugin:' + get_plugin_name_by_class(self.__class__)
)
@ -264,6 +267,7 @@ class AsyncRunnablePlugin(RunnablePlugin, ABC):
"""
Initialize an event loop and run the listener as a task.
"""
assert self._loop, 'The loop is not initialized'
asyncio.set_event_loop(self._loop)
self._task = self._loop.create_task(self._listen())

View File

@ -107,7 +107,7 @@ def get_plugin_class_by_name(plugin_name) -> Optional[type]:
return None
def get_plugin_name_by_class(plugin) -> Optional[str]:
def get_plugin_name_by_class(plugin) -> str:
"""Gets the common name of a plugin (e.g. "music.mpd" or "media.vlc") given its class."""
from platypush.plugins import Plugin