From 79e1b77491ed76a076ca53ed2e4082317ffedbf5 Mon Sep 17 00:00:00 2001 From: Clif Bratcher Date: Sun, 19 May 2024 16:44:12 -0400 Subject: [PATCH] Shift error checking up the stack --- simplecli/simplecli.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/simplecli/simplecli.py b/simplecli/simplecli.py index 806a8aa..29aedfb 100644 --- a/simplecli/simplecli.py +++ b/simplecli/simplecli.py @@ -311,8 +311,6 @@ def params_to_kwargs( missing_params = [] try: for param in params: - if param.annotation is Empty: - exit("ERROR: All wrapped function parameters need type hints!") # Positional arguments take precedence if pos_args: param.set_value(pos_args.pop(0)) @@ -406,19 +404,18 @@ def wrap(func: Callable[..., Any]) -> Callable[..., Any]: def code_to_ordered_params(code: Callable[..., Any]) -> OrderedDict: signature = inspect.signature(code) - empty = inspect._empty - return OrderedDict( - ( - k, - Param( - name=v.name, - default=Empty if v.default is empty else v.default, - annotation=Empty if v.annotation is empty else v.annotation, - kind=v.kind, - ), + result = OrderedDict() + + for k, v in signature.parameters.items(): + if v.annotation is inspect._empty: + exit("ERROR: All wrapped function parameters need type hints!") + result[k] = Param( + name=v.name, + default=Empty if v.default is inspect._empty else v.default, + annotation=v.annotation, + kind=v.kind, ) - for k, v in signature.parameters.items() - ) + return result def process_comment(