Skip to content

Commit

Permalink
actualy added type converting for annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomatree authored Aug 23, 2019
1 parent b67807b commit ddd85bc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions actioneer/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ def __init__(self, func, aliases: List[str] = [], *,
options: Dict[str, Callable] = {},
options_aliases: Dict[str, str] = {}, flags: List[str] = [],
flags_aliases: Dict[str, str] = {}, performer=None):

self.subs = {}
self.name = func.__name__
self.func = func
self.aliases = aliases
self.casts = [self.make_cast(param)
self.casts = [self.get_cast(param)
for param in signature(func).parameters.values()
if param.kind == Parameter.VAR_POSITIONAL]
self.options = options
Expand All @@ -29,9 +30,12 @@ def __init__(self, func, aliases: List[str] = [], *,
bool: bool_from_str
}

def make_cast(self, param):
def get_cast(self, param):
return self.overrides.get(param, param)

def make_cast(self, args):
return [cast(arg) for cast, arg in zip(args, self.casts)]

def invoke(self, args: List[str] = [], ctx: List[Any] = []):
ctx = {type(a): a for a in ctx}
sub = self.subs.get(args[0])
Expand All @@ -43,6 +47,7 @@ def invoke(self, args: List[str] = [], ctx: List[Any] = []):
if v.kind == Parameter.KEYWORD_ONLY}

ctxs = {name: ctx[value] for name, value in name_annots.items()}
args =
self.func(*args, **ctxs)
except Exception as e:
if self.error_handler:
Expand Down

0 comments on commit ddd85bc

Please sign in to comment.