Skip to content

Commit

Permalink
use fields instead of inspect (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 authored Apr 4, 2022
1 parent 5abda70 commit b1d7e02
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions npe2/_dynamic_plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import inspect
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -31,7 +30,7 @@
C = TypeVar("C", bound=BaseModel)
T = TypeVar("T", bound=Callable[..., Any])

COMMAND_PARAMS = inspect.signature(CommandContribution).parameters

# a mapping of contribution type to string name in the ContributionPoints
# e.g. {ReaderContribution: 'readers'}
CONTRIB_NAMES = {v.type_: k for k, v in ContributionPoints.__fields__.items()}
Expand Down Expand Up @@ -206,7 +205,11 @@ def _store_command(self, func: T, kwargs: dict) -> dict:
"""Create a new command contribution for `func`"""
kwargs.setdefault("title", func.__name__)
kwargs.setdefault("id", f"{self.plugin.manifest.name}.{func.__name__}")
cmd_kwargs = {k: kwargs.pop(k) for k in list(kwargs) if k in COMMAND_PARAMS}
cmd_kwargs = {
k: kwargs.pop(k)
for k in list(kwargs)
if k in CommandContribution.__fields__
}
cmd = CommandContribution(**cmd_kwargs)
self.commands.append(cmd)
self.plugin.plugin_manager.commands.register(cmd.id, func)
Expand Down

0 comments on commit b1d7e02

Please sign in to comment.