From 34427810d7e3c2a3d3257c3783f394d041a2c7d7 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Wed, 8 Jul 2020 15:58:56 +0200 Subject: Improve code quality --- web-server/opendc/util/parameter_checker.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'web-server') diff --git a/web-server/opendc/util/parameter_checker.py b/web-server/opendc/util/parameter_checker.py index 214dfa9d..d1256009 100644 --- a/web-server/opendc/util/parameter_checker.py +++ b/web-server/opendc/util/parameter_checker.py @@ -46,20 +46,18 @@ def _incorrect_parameter(params_required, params_actual, parent=''): except: return '{}.{}'.format(parent, param_name) - if param_required == 'int' and not isinstance(param_actual, int): - return '{}.{}'.format(parent, param_name) - - if param_required == 'float' and not isinstance(param_actual, float): - return '{}.{}'.format(parent, param_name) - - if param_required == 'bool' and not isinstance(param_actual, bool): - return '{}.{}'.format(parent, param_name) - - if param_required == 'string' and not isinstance(param_actual, str) and not isinstance(param_actual, int): - return '{}.{}'.format(parent, param_name) - - if param_required.startswith('list') and not isinstance(param_actual, list): - return '{}.{}'.format(parent, param_name) + type_pairs = [ + ('int', (int,)), + ('float', (float,)), + ('bool', (bool,)), + ('string', (str, int)), + ('list', (list,)), + ] + + for str_type, actual_types in type_pairs: + if param_required == str_type and all(not isinstance(param_actual, t) + for t in actual_types): + return '{}.{}'.format(parent, param_name) return None -- cgit v1.2.3