From db76bb8e0bff0ad36fbf202388081ad59bd97628 Mon Sep 17 00:00:00 2001 From: Pavel Muhortov Date: Sun, 18 Jun 2023 08:12:18 +0300 Subject: [PATCH] add Do.args_valid() --- cctv-scheduler.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cctv-scheduler.py b/cctv-scheduler.py index 722c2d2..f22d7dd 100644 --- a/cctv-scheduler.py +++ b/cctv-scheduler.py @@ -1524,6 +1524,37 @@ class FFmpeg: return None +class Do(): + """Set of various methods (functions) for routine. + """ + @staticmethod + def args_valid(arguments: dict, annotations: dict) -> bool: + """Arguments type validating by annotations. + + Args: + arguments (dict): 'locals()' immediately after starting the function. + annotations (dict): function.name.__annotations__. + + Raises: + TypeError: type of argument is not equal type in annotation. + + Returns: + bool: True if argument types are valid. + """ + for var_name, var_type in annotations.items(): + if not var_name == 'return': + if not isinstance(arguments[var_name], var_type): + raise TypeError("" + + "type of '" + + var_name + + "' = " + + str(arguments[var_name]) + + " is not " + + str(var_type) + ) + return True + + if __name__ == "__main__": time_start = datetime.now()